Module: kamailio
Branch: master
Commit: 0b9442b14adccdc7305ba222833a149e64488d66
URL:
https://github.com/kamailio/kamailio/commit/0b9442b14adccdc7305ba222833a149…
Author: Henning Westerholt <hw(a)gilawa.com>
Committer: Henning Westerholt <hw(a)gilawa.com>
Date: 2023-03-29T08:23:13Z
acc: convert to memory logging helper, properly free memory in case of errors
---
Modified: src/modules/acc/acc.c
Modified: src/modules/acc/acc_cdr.c
Modified: src/modules/acc/acc_extra.c
---
Diff:
https://github.com/kamailio/kamailio/commit/0b9442b14adccdc7305ba222833a149…
Patch:
https://github.com/kamailio/kamailio/commit/0b9442b14adccdc7305ba222833a149…
---
diff --git a/src/modules/acc/acc.c b/src/modules/acc/acc.c
index 6e9d8ed5a48..216ff7685fc 100644
--- a/src/modules/acc/acc.c
+++ b/src/modules/acc/acc.c
@@ -634,32 +634,37 @@ void acc_api_set_arrays(acc_info_t *inf)
int acc_arrays_alloc(void) {
if ((val_arr = pkg_mallocxz((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) *
sizeof(str))) == NULL) {
- LM_ERR("failed to alloc val_arr\n");
+ PKG_MEM_ERROR_FMT("failed to alloc val_arr\n");
return -1;
}
if ((int_arr = pkg_mallocxz((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) *
sizeof(int))) == NULL) {
- LM_ERR("failed to alloc int_arr\n");
+ PKG_MEM_ERROR_FMT("failed to alloc int_arr\n");
+ acc_arrays_free();
return -1;
}
if ((type_arr = pkg_mallocxz((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) *
sizeof(char))) == NULL) {
- LM_ERR("failed to alloc type_arr\n");
+ PKG_MEM_ERROR_FMT("failed to alloc type_arr\n");
+ acc_arrays_free();
return -1;
}
if ((log_attrs = pkg_mallocxz((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) *
sizeof(str))) == NULL) {
- LM_ERR("failed to alloc log_attrs\n");
+ PKG_MEM_ERROR_FMT("failed to alloc log_attrs\n");
+ acc_arrays_free();
return -1;
}
if ((db_keys = pkg_mallocxz((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) *
sizeof(db_key_t))) == NULL) {
- LM_ERR("failed to alloc db_keys\n");
+ PKG_MEM_ERROR_FMT("failed to alloc db_keys\n");
+ acc_arrays_free();
return -1;
}
if ((db_vals = pkg_mallocxz((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) *
sizeof(db_val_t))) == NULL) {
- LM_ERR("failed to alloc db_vals\n");
+ PKG_MEM_ERROR_FMT("failed to alloc db_vals\n");
+ acc_arrays_free();
return -1;
}
diff --git a/src/modules/acc/acc_cdr.c b/src/modules/acc/acc_cdr.c
index d15340b3481..0afa7630352 100644
--- a/src/modules/acc/acc_cdr.c
+++ b/src/modules/acc/acc_cdr.c
@@ -1028,32 +1028,37 @@ void cdr_api_set_arrays(cdr_info_t *inf)
int cdr_arrays_alloc(void) {
if ((cdr_attrs = pkg_malloc((MAX_CDR_CORE + cdr_extra_size) * sizeof(str))) == NULL) {
- LM_ERR("failed to alloc cdr_attrs\n");
+ PKG_MEM_ERROR_FMT("failed to alloc cdr_attrs\n");
return -1;
}
if ((cdr_value_array = pkg_malloc((MAX_CDR_CORE + cdr_extra_size) * sizeof(str))) ==
NULL) {
- LM_ERR("failed to alloc cdr_value_array\n");
+ PKG_MEM_ERROR_FMT("failed to alloc cdr_value_array\n");
+ cdr_arrays_free();
return -1;
}
if ((cdr_int_array = pkg_malloc((MAX_CDR_CORE + cdr_extra_size) * sizeof(int))) == NULL)
{
- LM_ERR("failed to alloc cdr_int_array\n");
+ PKG_MEM_ERROR_FMT("failed to alloc cdr_int_array\n");
+ cdr_arrays_free();
return -1;
}
if ((cdr_type_array = pkg_malloc((MAX_CDR_CORE + cdr_extra_size) * sizeof(char))) ==
NULL) {
- LM_ERR("failed to alloc cdr_type_array\n");
+ PKG_MEM_ERROR_FMT("failed to alloc cdr_type_array\n");
+ cdr_arrays_free();
return -1;
}
if ((db_cdr_keys = pkg_malloc((MAX_CDR_CORE + cdr_extra_size) * sizeof(db_key_t))) ==
NULL) {
- LM_ERR("failed to alloc db_cdr_keys\n");
+ PKG_MEM_ERROR_FMT("failed to alloc db_cdr_keys\n");
+ cdr_arrays_free();
return -1;
}
if ((db_cdr_vals = pkg_malloc((MAX_CDR_CORE + cdr_extra_size) * sizeof(db_val_t))) ==
NULL) {
- LM_ERR("failed to alloc db_cdr_vals\n");
+ PKG_MEM_ERROR_FMT("failed to alloc db_cdr_vals\n");
+ cdr_arrays_free();
return -1;
}
diff --git a/src/modules/acc/acc_extra.c b/src/modules/acc/acc_extra.c
index 6205ba1a17d..dc0e1259990 100644
--- a/src/modules/acc/acc_extra.c
+++ b/src/modules/acc/acc_extra.c
@@ -386,7 +386,7 @@ int acc_extra_arrays_alloc(void) {
}
if ((int_buf = pkg_malloc((INT2STR_MAX_LEN * acc_int_buf_size) * sizeof(char))) == NULL)
{
- LM_ERR("failed to alloc int_buf\n");
+ PKG_MEM_ERROR_FMT("failed to alloc int_buf\n");
return -1;
}