Skip to content

Commit

Permalink
acc: convert to memory logging helper, properly free memory in case o…
Browse files Browse the repository at this point in the history
…f errors
  • Loading branch information
henningw committed Mar 29, 2023
1 parent ba36510 commit 0b9442b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
17 changes: 11 additions & 6 deletions src/modules/acc/acc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
17 changes: 11 additions & 6 deletions src/modules/acc/acc_cdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/acc/acc_extra.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 0b9442b

Please sign in to comment.