Skip to content

Commit

Permalink
lcr: convert to memory error logging helper, add some missing mem cle…
Browse files Browse the repository at this point in the history
…anup on error
  • Loading branch information
pantelisk98 authored and henningw committed May 4, 2023
1 parent b002a5d commit 8b9e4db
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
11 changes: 8 additions & 3 deletions src/modules/lcr/hash.c
Expand Up @@ -48,7 +48,7 @@ int rule_hash_table_insert(struct rule_info **hash_table, unsigned int lcr_id,

rule = (struct rule_info *)shm_malloc(sizeof(struct rule_info));
if(rule == NULL) {
LM_ERR("no shm memory for rule hash table entry\n");
SHM_MEM_ERROR_FMT("for rule hash table entry\n");
if(from_uri_re)
shm_free(from_uri_re);
if(request_uri_re)
Expand Down Expand Up @@ -97,7 +97,12 @@ int rule_hash_table_insert(struct rule_info **hash_table, unsigned int lcr_id,
/* Add rule_id info to rule_id hash table */
rid = (struct rule_id_info *)pkg_malloc(sizeof(struct rule_id_info));
if(rid == NULL) {
LM_ERR("no pkg memory for rule_id hash table entry\n");
PKG_MEM_ERROR_FMT("for rule_id hash table entry\n");
if(from_uri_re)
shm_free(from_uri_re);
if(request_uri_re)
shm_free(request_uri_re);
shm_free(rule);
return 0;
}
memset(rid, 0, sizeof(struct rule_id_info));
Expand Down Expand Up @@ -143,7 +148,7 @@ int rule_hash_table_insert_target(struct rule_info **hash_table,

target = (struct target *)shm_malloc(sizeof(struct target));
if(target == NULL) {
LM_ERR("cannot allocate memory for rule target\n");
SHM_MEM_ERROR_FMT("for rule target\n");
return 0;
}

Expand Down
16 changes: 8 additions & 8 deletions src/modules/lcr/lcr_mod.c
Expand Up @@ -704,7 +704,7 @@ static int mod_init(void)
rule_pt = (struct rule_info ***)shm_malloc(
sizeof(struct rule_info **) * (lcr_count_param + 1));
if(rule_pt == 0) {
LM_ERR("no memory for rule hash table pointer table\n");
SHM_MEM_ERROR_FMT("for rule hash table pointer table\n");
goto err;
}
memset(rule_pt, 0, sizeof(struct rule_info **) * (lcr_count_param + 1));
Expand All @@ -715,7 +715,7 @@ static int mod_init(void)
rule_pt[i] = (struct rule_info **)shm_malloc(
sizeof(struct rule_info *) * (lcr_rule_hash_size_param + 1));
if(rule_pt[i] == 0) {
LM_ERR("no memory for rules hash table\n");
SHM_MEM_ERROR_FMT("for rules hash table\n");
goto err;
}
memset(rule_pt[i], 0,
Expand All @@ -728,7 +728,7 @@ static int mod_init(void)
gw_pt = (struct gw_info **)shm_malloc(
sizeof(struct gw_info *) * (lcr_count_param + 1));
if(gw_pt == 0) {
LM_ERR("no memory for gw table pointer table\n");
SHM_MEM_ERROR_FMT("for gw table pointer table\n");
goto err;
}
memset(gw_pt, 0, sizeof(struct gw_info *) * (lcr_count_param + 1));
Expand All @@ -742,7 +742,7 @@ static int mod_init(void)
gw_pt[i] = (struct gw_info *)shm_malloc(
sizeof(struct gw_info) * (lcr_gw_count_param + 1));
if(gw_pt[i] == 0) {
LM_ERR("no memory for gw table\n");
SHM_MEM_ERROR_FMT("for gw table\n");
goto err;
}
memset(gw_pt[i], 0, sizeof(struct gw_info) * (lcr_gw_count_param + 1));
Expand Down Expand Up @@ -892,7 +892,7 @@ static pcre *reg_ex_comp(const char *pattern)
result = (pcre *)shm_malloc(size);
if(result == NULL) {
pcre_free(re);
LM_ERR("not enough shared memory for compiled PCRE pattern\n");
SHM_MEM_ERROR_FMT("for compiled PCRE pattern\n");
return (pcre *)0;
}
memcpy(result, re, size);
Expand Down Expand Up @@ -1032,7 +1032,7 @@ static int prefix_len_insert(
if(this->prefix_len < prefix_len) {
lcr_rec = shm_malloc(sizeof(struct rule_info));
if(lcr_rec == NULL) {
LM_ERR("no shared memory for rule_info\n");
SHM_MEM_ERROR_FMT("for rule_info\n");
return 0;
}
memset(lcr_rec, 0, sizeof(struct rule_info));
Expand All @@ -1047,7 +1047,7 @@ static int prefix_len_insert(

lcr_rec = shm_malloc(sizeof(struct rule_info));
if(lcr_rec == NULL) {
LM_ERR("no shared memory for rule_info\n");
SHM_MEM_ERROR_FMT("for rule_info\n");
return 0;
}
memset(lcr_rec, 0, sizeof(struct rule_info));
Expand Down Expand Up @@ -1451,7 +1451,7 @@ int reload_tables()
rule_id_hash_table = pkg_malloc(
sizeof(struct rule_id_info *) * lcr_rule_hash_size_param);
if(!rule_id_hash_table) {
LM_ERR("no pkg memory for rule_id hash table\n");
PKG_MEM_ERROR_FMT("for rule_id hash table\n");
goto err;
}
memset(rule_id_hash_table, 0,
Expand Down

0 comments on commit 8b9e4db

Please sign in to comment.