core: use generic PKG_MEM_ERROR, SHM_ERROR and _CRITICAL helper defines in core
authorHenning Westerholt <hw@kamailio.org>
Sun, 23 Dec 2018 21:31:03 +0000 (22:31 +0100)
committerHenning Westerholt <hw@kamailio.org>
Sun, 23 Dec 2018 21:37:22 +0000 (22:37 +0100)
    - refactoring of the core to use generic PKG_MEM_ERROR, SHM_ERROR,
      PKG_MEM_CRITICAL, SHM_MEM_CRITICAL and SYS_MEM_ERROR helper defines
    - unify many different error messages in different spellings
    - add a few missing error handler for allocation errors after (found
      with a complete review of all memory allocation functions in core)
    - no other functional changes, change has been reviewed two times

86 files changed:
src/core/action.c
src/core/cfg.lex
src/core/cfg.y
src/core/cfg/cfg.c
src/core/cfg/cfg_ctx.c
src/core/cfg/cfg_script.c
src/core/cfg/cfg_select.c
src/core/cfg/cfg_struct.c
src/core/cfg_parser.c
src/core/core_cmd.c
src/core/counters.c
src/core/data_lump.c
src/core/data_lump_rpl.c
src/core/dns_cache.c
src/core/dset.c
src/core/dst_blacklist.c
src/core/error.c
src/core/flags.c
src/core/forward.c
src/core/io_wait.c
src/core/ip_addr.c
src/core/kemi.c
src/core/lock_alloc.h
src/core/locking.c
src/core/mod_fix.c
src/core/modparam.c
src/core/msg_translator.c
src/core/name_alias.h
src/core/nonsip_hooks.c
src/core/parser/contact/contact.c
src/core/parser/contact/parse_contact.c
src/core/parser/digest/digest.c
src/core/parser/msg_parser.c
src/core/parser/parse_addr_spec.c
src/core/parser/parse_allow.c
src/core/parser/parse_content.c
src/core/parser/parse_date.c
src/core/parser/parse_disposition.c
src/core/parser/parse_diversion.c
src/core/parser/parse_event.c
src/core/parser/parse_expires.c
src/core/parser/parse_fline.c
src/core/parser/parse_from.c
src/core/parser/parse_identity.c
src/core/parser/parse_identityinfo.c
src/core/parser/parse_param.c
src/core/parser/parse_ppi_pai.c
src/core/parser/parse_refer_to.c
src/core/parser/parse_require.c
src/core/parser/parse_rpid.c
src/core/parser/parse_rr.c
src/core/parser/parse_sipifmatch.c
src/core/parser/parse_subscription_state.c
src/core/parser/parse_supported.c
src/core/parser/parse_via.c
src/core/parser/sdp/sdp.c
src/core/parser/sdp/sdp_helpr_funcs.c
src/core/ppcfg.c
src/core/proxy.c
src/core/pt.c
src/core/pvapi.c
src/core/re.c
src/core/receive.c
src/core/resolve.c
src/core/route.c
src/core/route_struct.c
src/core/rpc_lookup.c
src/core/rvalue.c
src/core/script_cb.c
src/core/select.c
src/core/select_buf.c
src/core/sip_msg_clone.c
src/core/socket_info.c
src/core/sr_module.c
src/core/stats.c
src/core/str.c
src/core/str_hash.h
src/core/switch.c
src/core/tcp_main.c
src/core/tcp_read.c
src/core/timer.c
src/core/timer_proc.c
src/core/udp_server.c
src/core/usr_avp.c
src/core/ut.c
src/core/xavp.c

index 2dd41a4..ca55861 100644 (file)
@@ -752,7 +752,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
                                        len=strlen(a->val[0].u.string);
                                        msg->new_uri.s=pkg_malloc(len+1);
                                        if (msg->new_uri.s==0){
-                                               LM_ERR("memory allocation failure\n");
+                                               PKG_MEM_ERROR;
                                                ret=E_OUT_OF_MEM;
                                                goto error;
                                        }
@@ -802,7 +802,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
 
                                new_uri=pkg_malloc(MAX_URI_SIZE);
                                if (new_uri==0){
-                                       LM_ERR("memory allocation failure\n");
+                                       PKG_MEM_ERROR;
                                        ret=E_OUT_OF_MEM;
                                        goto error;
                                }
index 5e9296c..6e4d697 100644 (file)
@@ -1433,8 +1433,7 @@ static char* addstr(struct str_buf* dst_b, char* src, int len)
 
        return dst_b->s;
 error:
-       LM_CRIT("lex: memory allocation error\n");
-       LM_CRIT("lex: try to increase pkg size with -M parameter\n");
+       PKG_MEM_CRITICAL;
        exit(-1);
 }
 
@@ -1602,7 +1601,7 @@ static int sr_push_yy_state(char *fin, int mode)
                newf = (char*)pkg_malloc(x-tmpfiname+strlen(fbuf)+2);
                if(newf==0)
                {
-                       LM_CRIT("no more pkg\n");
+                       PKG_MEM_CRITICAL;
                        return -1;
                }
                newf[0] = '\0';
@@ -1664,7 +1663,7 @@ static int sr_push_yy_state(char *fin, int mode)
                {
                        if(newf!=fbuf)
                                pkg_free(newf);
-                       LM_CRIT("no more pkg\n");
+                       PKG_MEM_CRITICAL;
                        return -1;
                }
                if(newf==fbuf)
@@ -1673,7 +1672,7 @@ static int sr_push_yy_state(char *fin, int mode)
                        if(fn->fname==0)
                        {
                                pkg_free(fn);
-                               LM_CRIT("no more pkg!\n");
+                               PKG_MEM_CRITICAL;
                                return -1;
                        }
                        strcpy(fn->fname, fbuf);
@@ -1793,7 +1792,7 @@ int pp_define(int len, const char * text)
        pp_defines[pp_num_defines].name.len = len;
        pp_defines[pp_num_defines].name.s = (char*)pkg_malloc(len+1);
        if(pp_defines[pp_num_defines].name.s==NULL) {
-               LM_CRIT("no more memory to define: %.*s\n", len, text);
+               PKG_MEM_CRITICAL;
                return -1;
        }
        memcpy(pp_defines[pp_num_defines].name.s, text, len);
index 6b8de03..cb886fa 100644 (file)
@@ -649,7 +649,7 @@ listen_id:
                        } else {
                                $$=pkg_malloc(strlen(tmp)+1);
                                if ($$==0) {
-                                       LM_CRIT("cfg. parser: out of memory.\n");
+                                       PKG_MEM_CRITICAL;
                                } else {
                                        strncpy($$, tmp, strlen(tmp)+1);
                                }
@@ -659,7 +659,7 @@ listen_id:
        | STRING {
                $$=pkg_malloc(strlen($1)+1);
                if ($$==0) {
-                               LM_CRIT("cfg. parser: out of memory.\n");
+                               PKG_MEM_CRITICAL;
                } else {
                                strncpy($$, $1, strlen($1)+1);
                }
@@ -668,7 +668,7 @@ listen_id:
                if ($1){
                        $$=pkg_malloc(strlen($1)+1);
                        if ($$==0) {
-                                       LM_CRIT("cfg. parser: out of memory.\n");
+                                       PKG_MEM_CRITICAL;
                        } else {
                                        strncpy($$, $1, strlen($1)+1);
                        }
@@ -1470,7 +1470,7 @@ assign_stm:
        | ADVERTISED_PORT EQUAL NUMBER {
                tmp=int2str($3, &i_tmp);
                if ((default_global_port.s=pkg_malloc(i_tmp))==0) {
-                       LM_CRIT("cfg. parser: out of memory.\n");
+                       PKG_MEM_CRITICAL;
                        default_global_port.len=0;
                } else {
                        default_global_port.len=i_tmp;
@@ -1789,7 +1789,7 @@ ipv4:
        NUMBER DOT NUMBER DOT NUMBER DOT NUMBER {
                $$=pkg_malloc(sizeof(struct ip_addr));
                if ($$==0) {
-                       LM_CRIT("cfg. parser: out of memory.\n");
+                       PKG_MEM_CRITICAL;
                } else {
                        memset($$, 0, sizeof(struct ip_addr));
                        $$->af=AF_INET;
@@ -1818,7 +1818,7 @@ ipv6addr:
        IPV6ADDR {
                $$=pkg_malloc(sizeof(struct ip_addr));
                if ($$==0) {
-                       LM_CRIT("cfg. parser: out of memory.\n");
+                       PKG_MEM_CRITICAL;
                } else {
                        memset($$, 0, sizeof(struct ip_addr));
                        $$->af=AF_INET6;
@@ -2271,8 +2271,7 @@ host:
                if ($1){
                        $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
                        if ($$==0) {
-                               LM_CRIT("cfg. parser: memory allocation"
-                                                       " failure while parsing host\n");
+                               PKG_MEM_CRITICAL;
                        } else {
                                memcpy($$, $1, strlen($1));
                                $$[strlen($1)]='.';
@@ -2287,8 +2286,7 @@ host:
                if ($1){
                        $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
                        if ($$==0) {
-                               LM_CRIT("cfg. parser: memory allocation"
-                                                       " failure while parsing host\n");
+                               PKG_MEM_CRITICAL;
                        } else {
                                memcpy($$, $1, strlen($1));
                                $$[strlen($1)]='-';
@@ -2308,8 +2306,11 @@ host_if_id: ID
                | NUMBER {
                        /* get string version */
                        $$=pkg_malloc(strlen(yy_number_str)+1);
-                       if ($$)
+                       if ($$==0) {
+                               PKG_MEM_ERROR;
+                       } else {
                                strcpy($$, yy_number_str);
+                       }
                }
                ;
 
@@ -2319,8 +2320,7 @@ host_or_if:
                if ($1){
                        $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
                        if ($$==0) {
-                               LM_CRIT("cfg. parser: memory allocation"
-                                                       " failure while parsing host/interface name\n");
+                               PKG_MEM_CRITICAL;
                        } else {
                                memcpy($$, $1, strlen($1));
                                $$[strlen($1)]='.';
@@ -2335,8 +2335,7 @@ host_or_if:
                if ($1){
                        $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
                        if ($$==0) {
-                               LM_CRIT("cfg. parser: memory allocation"
-                                                       " failure while parsing host/interface name\n");
+                               PKG_MEM_CRITICAL;
                        } else {
                                memcpy($$, $1, strlen($1));
                                $$[strlen($1)]='-';
@@ -3294,7 +3293,7 @@ cmd:
        | SET_ADV_ADDRESS LPAREN listen_id RPAREN {
                $$=0;
                if ((str_tmp=pkg_malloc(sizeof(str)))==0) {
-                       LM_CRIT("cfg. parser: out of memory.\n");
+                       PKG_MEM_CRITICAL;
                } else {
                        str_tmp->s=$3;
                        str_tmp->len=$3?strlen($3):0;
@@ -3308,10 +3307,10 @@ cmd:
                $$=0;
                tmp=int2str($3, &i_tmp);
                if ((str_tmp=pkg_malloc(sizeof(str)))==0) {
-                       LM_CRIT("cfg. parser: out of memory.\n");
+                       PKG_MEM_CRITICAL;
                } else {
                        if ((str_tmp->s=pkg_malloc(i_tmp))==0) {
-                               LM_CRIT("cfg. parser: out of memory.\n");
+                               PKG_MEM_CRITICAL;
                        } else {
                                memcpy(str_tmp->s, tmp, i_tmp);
                                str_tmp->len=i_tmp;
@@ -3680,7 +3679,7 @@ static struct name_lst* mk_name_lst(char* host, int flags)
        if (host==0) return 0;
        l=pkg_malloc(sizeof(struct name_lst));
        if (l==0) {
-               LM_CRIT("cfg. parser: out of memory.\n");
+               PKG_MEM_CRITICAL;
        } else {
                l->name=host;
                l->flags=flags;
@@ -3696,7 +3695,7 @@ static struct socket_id* mk_listen_id(char* host, int proto, int port)
        if (host==0) return 0;
        l=pkg_malloc(sizeof(struct socket_id));
        if (l==0) {
-               LM_CRIT("cfg. parser: out of memory.\n");
+               PKG_MEM_CRITICAL;
        } else {
                l->addr_lst=mk_name_lst(host, 0);
                if (l->addr_lst==0){
@@ -3731,7 +3730,7 @@ static struct socket_id* mk_listen_id2(struct name_lst* addr_l, int proto,
        if (addr_l==0) return 0;
        l=pkg_malloc(sizeof(struct socket_id));
        if (l==0) {
-               LM_CRIT("cfg. parser: out of memory.\n");
+               PKG_MEM_CRITICAL;
        } else {
                l->flags=addr_l->flags;
                l->port=port;
index 21a7d3b..3822a9c 100644 (file)
@@ -49,7 +49,7 @@ int cfg_declare(char *group_name, cfg_def_t *def, void *values, int def_size,
 
        mapping = (cfg_mapping_t *)pkg_malloc(sizeof(cfg_mapping_t)*num);
        if (!mapping) {
-               LM_ERR("not enough memory\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        memset(mapping, 0, sizeof(cfg_mapping_t)*num);
@@ -212,7 +212,7 @@ int cfg_declare_str(char *group_name, char *var_name, char *val, char *descr)
                len = strlen(val);
                var->val.s.s = (char *)pkg_malloc(sizeof(char) * (len + 1));
                if (!var->val.s.s) {
-                       LM_ERR("not enough memory\n");
+                       PKG_MEM_ERROR;
                        return -1;
                }
                memcpy(var->val.s.s, val, len + 1);
index 9e60571..733e0b4 100644 (file)
@@ -46,7 +46,7 @@ int cfg_register_ctx(cfg_ctx_t **handle, cfg_on_declare on_declare_cb)
         * must be in shm mem anyway */
        ctx = (cfg_ctx_t *)shm_malloc(sizeof(cfg_ctx_t));
        if (!ctx) {
-               LM_ERR("not enough shm memory\n");
+               SHM_MEM_ERROR;
                return -1;
        }
        memset(ctx, 0, sizeof(cfg_ctx_t));
@@ -183,7 +183,7 @@ int convert_val(unsigned int val_type, void *val,
                                if (temp_string) pkg_free(temp_string);
                                temp_string = (char *)pkg_malloc(sizeof(char) * (((str *)val)->len + 1));
                                if (!temp_string) {
-                                       LM_ERR("not enough memory\n");
+                                       PKG_MEM_ERROR;
                                        return -1;
                                }
                                memcpy(temp_string, ((str *)val)->s, ((str *)val)->len);
@@ -427,7 +427,7 @@ int cfg_set_now(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id, str *va
                                var->def->on_set_child_cb,
                                var->def->type);
                if (!child_cb) {
-                       LM_ERR("not enough shm memory\n");
+                       SHM_MEM_ERROR;
                        goto error0;
                }
        }
@@ -558,7 +558,7 @@ int cfg_set_now(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id, str *va
                        replaced = (void **)shm_malloc(sizeof(void *)
                                        * ((old_string?1:0) + (new_array?1:0) + 1));
                        if (!replaced) {
-                               LM_ERR("not enough shm memory\n");
+                               SHM_MEM_ERROR;
                                goto error;
                        }
                        i = 0;
@@ -782,7 +782,7 @@ int cfg_set_delayed(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id,
                if (ctx->changed_first) {
                        temp_handle = (unsigned char *)pkg_malloc(group->size);
                        if (!temp_handle) {
-                               LM_ERR("not enough memory\n");
+                               PKG_MEM_ERROR;
                                goto error;
                        }
                        temp_handle_created = 1;
@@ -831,7 +831,7 @@ int cfg_set_delayed(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id,
                + ((val_type != CFG_VAR_UNSET) ? cfg_var_size(var) : 0);
        changed = (cfg_changed_var_t *)shm_malloc(size);
        if (!changed) {
-               LM_ERR("not enough shm memory\n");
+               SHM_MEM_ERROR;
                goto error;
        }
        memset(changed, 0, size);
@@ -1063,7 +1063,7 @@ int cfg_commit(cfg_ctx_t *ctx)
                size = sizeof(void *)*(replaced_num + 1);
                replaced = (void **)shm_malloc(size);
                if (!replaced) {
-                       LM_ERR("not enough shm memory\n");
+                       SHM_MEM_ERROR;
                        goto error0;
                }
                memset(replaced, 0 , size);
@@ -1635,7 +1635,7 @@ int cfg_add_group_inst(cfg_ctx_t *ctx, str *group_name, unsigned int group_id)
                 * they will be freed when the old block is freed */
                replaced = (void **)shm_malloc(sizeof(void *) * 2);
                if (!replaced) {
-                       LM_ERR("not enough shm memory\n");
+                       SHM_MEM_ERROR;
                        goto error;
                }
                replaced[0] = CFG_GROUP_META(*cfg_global, group)->array;
@@ -1740,7 +1740,7 @@ int cfg_del_group_inst(cfg_ctx_t *ctx, str *group_name, unsigned int group_id)
 
                replaced = (void **)shm_malloc(sizeof(void *) * (num + 2));
                if (!replaced) {
-                       LM_ERR("not enough shm memory\n");
+                       SHM_MEM_ERROR;
                        goto error;
                }
 
index 9873f70..80257a4 100644 (file)
@@ -139,7 +139,7 @@ cfg_script_var_t *new_cfg_script_var(char *gname, char *vname, unsigned int type
        return var;
 
 error:
-       LM_ERR("not enough memory\n");
+       PKG_MEM_ERROR;
        return NULL;
 }
 
@@ -188,7 +188,7 @@ int cfg_set_script_var(cfg_group_t *group, str *var_name,
                                        s.len = ((str *)v)->len;
                                        s.s = pkg_malloc(sizeof(char) * (s.len + 1));
                                        if (!s.s) {
-                                               LM_ERR("not enough memory\n");
+                                               PKG_MEM_ERROR;
                                                goto error;
                                        }
                                        memcpy(s.s, ((str *)v)->s, s.len);
@@ -325,7 +325,7 @@ error:
        if (def) pkg_free(def);
        if (handle) pkg_free(handle);
 
-       LM_ERR("not enough memory\n");
+       PKG_MEM_ERROR;
        return -1;
 }
 
index 175c6bd..30b99cf 100644 (file)
@@ -73,7 +73,7 @@ static int cfg_new_select(str *gname, str *vname, void **group_p, void **var_p)
        return 0;
 
 error:
-       LM_ERR("not enough memory\n");
+       PKG_MEM_ERROR;
        if (sel) {
                if (sel->gname.s) pkg_free(sel->gname.s);
                if (sel->vname.s) pkg_free(sel->vname.s);
index f7b1530..0e3f30a 100644 (file)
@@ -78,7 +78,7 @@ cfg_group_t *cfg_new_group(char *name, int name_len,
 
        group = (cfg_group_t *)pkg_malloc(sizeof(cfg_group_t)+name_len-1);
        if (!group) {
-               LM_ERR("not enough memory\n");
+               PKG_MEM_ERROR;
                return NULL;
        }
        memset(group, 0, sizeof(cfg_group_t)+name_len-1);
@@ -129,7 +129,7 @@ int cfg_clone_str(str *src, str *dst)
 
        c = (char *)shm_malloc(sizeof(char)*(src->len+1));
        if (!c) {
-               LM_ERR("not enough shm memory\n");
+               SHM_MEM_ERROR;
                return -1;
        }
        memcpy(c, src->s, src->len);
@@ -216,7 +216,7 @@ int cfg_shmize(void)
 
        block = (cfg_block_t*)shm_malloc(sizeof(cfg_block_t)+size-1);
        if (!block) {
-               LM_ERR("not enough shm memory\n");
+               SHM_MEM_ERROR;
                goto error;
        }
        memset(block, 0, sizeof(cfg_block_t)+size-1);
@@ -319,9 +319,10 @@ static void cfg_destory_groups(unsigned char *block)
 /* initiate the cfg framework */
 int sr_cfg_init(void)
 {
+       /* lock_alloc() is a define for shm_malloc */
        cfg_global_lock = lock_alloc();
        if (!cfg_global_lock) {
-               LM_ERR("not enough shm memory\n");
+               SHM_MEM_ERROR;
                goto error;
        }
        if (lock_init(cfg_global_lock) == 0) {
@@ -333,7 +334,7 @@ int sr_cfg_init(void)
 
        cfg_writer_lock = lock_alloc();
        if (!cfg_writer_lock) {
-               LM_ERR("not enough shm memory\n");
+               SHM_MEM_ERROR;
                goto error;
        }
        if (lock_init(cfg_writer_lock) == 0) {
@@ -345,21 +346,21 @@ int sr_cfg_init(void)
 
        cfg_global = (cfg_block_t **)shm_malloc(sizeof(cfg_block_t *));
        if (!cfg_global) {
-               LM_ERR("not enough shm memory\n");
+               SHM_MEM_ERROR;
                goto error;
        }
        *cfg_global = NULL;
 
        cfg_child_cb_first = (cfg_child_cb_t **)shm_malloc(sizeof(cfg_child_cb_t *));
        if (!cfg_child_cb_first) {
-               LM_ERR("not enough shm memory\n");
+               SHM_MEM_ERROR;
                goto error;
        }
        *cfg_child_cb_first = NULL;
 
        cfg_child_cb_last = (cfg_child_cb_t **)shm_malloc(sizeof(cfg_child_cb_t *));
        if (!cfg_child_cb_last) {
-               LM_ERR("not enough shm memory\n");
+               SHM_MEM_ERROR;
                goto error;
        }
        *cfg_child_cb_last = NULL;
@@ -624,7 +625,7 @@ cfg_block_t *cfg_clone_global(void)
 
        block = (cfg_block_t*)shm_malloc(sizeof(cfg_block_t)+cfg_block_size-1);
        if (!block) {
-               LM_ERR("not enough shm memory\n");
+               SHM_MEM_ERROR;
                return NULL;
        }
        memcpy(block, *cfg_global, sizeof(cfg_block_t)+cfg_block_size-1);
@@ -647,7 +648,7 @@ cfg_group_inst_t *cfg_clone_array(cfg_group_meta_t *meta, cfg_group_t *group)
        size = (sizeof(cfg_group_inst_t) + group->size - 1) * meta->num;
        new_array = (cfg_group_inst_t *)shm_malloc(size);
        if (!new_array) {
-               LM_ERR("not enough shm memory\n");
+               SHM_MEM_ERROR;
                return NULL;
        }
        memcpy(new_array, meta->array, size);
@@ -668,7 +669,7 @@ cfg_group_inst_t *cfg_extend_array(cfg_group_meta_t *meta, cfg_group_t *group,
        inst_size = sizeof(cfg_group_inst_t) + group->size - 1;
        new_array = (cfg_group_inst_t *)shm_malloc(inst_size * (meta->num + 1));
        if (!new_array) {
-               LM_ERR("not enough shm memory\n");
+               SHM_MEM_ERROR;
                return NULL;
        }
        /* Find the position of the new group in the array. The array is ordered
@@ -717,7 +718,7 @@ int cfg_collapse_array(cfg_group_meta_t *meta, cfg_group_t *group,
        inst_size = sizeof(cfg_group_inst_t) + group->size - 1;
        new_array = (cfg_group_inst_t *)shm_malloc(inst_size * (meta->num - 1));
        if (!new_array) {
-               LM_ERR("not enough shm memory\n");
+               SHM_MEM_ERROR;
                return -1;
        }
 
@@ -796,7 +797,7 @@ void cfg_install_global(cfg_block_t *block, void **replaced,
                                cb_last = cb_first;
                                cb_first->replaced = replaced;
                        } else {
-                               LM_ERR("not enough shm memory\n");
+                               SHM_MEM_ERROR;
                                /* Nothing more can be done here, the replaced strings are still needed,
                                 * they cannot be freed at this moment.
                                 */
@@ -827,7 +828,7 @@ cfg_child_cb_t *cfg_child_cb_new(str *gname, str *name,
 
        cb_struct = (cfg_child_cb_t *)shm_malloc(sizeof(cfg_child_cb_t));
        if (!cb_struct) {
-               LM_ERR("not enough shm memory\n");
+               SHM_MEM_ERROR;
                return NULL;
        }
        memset(cb_struct, 0, sizeof(cfg_child_cb_t));
@@ -923,7 +924,7 @@ int new_add_var(str *group_name, unsigned int group_id, str *var_name,
        add_var = (cfg_add_var_t *)pkg_malloc(sizeof(cfg_add_var_t) +
                        (type ? (var_name->len - 1) : 0));
        if (!add_var) {
-               LM_ERR("Not enough memory\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        memset(add_var, 0, sizeof(cfg_add_var_t) +
@@ -944,7 +945,7 @@ int new_add_var(str *group_name, unsigned int group_id, str *var_name,
                                if (len) {
                                        add_var->val.s.s = (char *)pkg_malloc(sizeof(char) * len);
                                        if (!add_var->val.s.s) {
-                                               LM_ERR("Not enough memory\n");
+                                               PKG_MEM_ERROR;
                                                goto error;
                                        }
                                        memcpy(add_var->val.s.s, ((str *)val)->s, len);
@@ -959,7 +960,7 @@ int new_add_var(str *group_name, unsigned int group_id, str *var_name,
                                        len = strlen((char *)val);
                                        add_var->val.ch = (char *)pkg_malloc(sizeof(char) * (len + 1));
                                        if (!add_var->val.ch) {
-                                               LM_ERR("Not enough memory\n");
+                                               PKG_MEM_ERROR;
                                                goto error;
                                        }
                                        memcpy(add_var->val.ch, (char *)val, len);
@@ -1049,7 +1050,7 @@ static int apply_add_var_list(cfg_block_t *block, cfg_group_t *group)
        size = (sizeof(cfg_group_inst_t) + group->size - 1) * num;
        new_array = (cfg_group_inst_t *)shm_malloc(size);
        if (!new_array) {
-               LM_ERR("not enough shm memory\n");
+               SHM_MEM_ERROR;
                return -1;
        }
        memset(new_array, 0, size);
index 7808615..7aa30ee 100644 (file)
@@ -287,6 +287,7 @@ static void print_token(cfg_token_t* token)
                        token->type, STR_FMT(&token->val),
                        token->start.line, token->start.col, 
                        token->end.line, token->end.col);
+                       PKG_MEM_ERROR;
        } else {
                for(i = 0, j = 0; i < token->val.len; i++) {
                        switch(token->val.s[i]) {
@@ -599,7 +600,7 @@ static char* get_base_name(str* filename)
        len = strlen(tmp2);
 
        if ((res = pkg_malloc(len + 1)) == NULL) {
-               ERR("cfg_parser: No memory left");
+               PKG_MEM_ERROR;
                goto error;
        }
        memcpy(res, tmp2, len + 1);
@@ -644,7 +645,7 @@ cfg_parser_t* cfg_parser_init(str* basedir, str* filename)
        if ((base = get_base_name(filename)) == NULL) goto error;
 
        if ((st = (cfg_parser_t*)pkg_malloc(sizeof(*st))) == NULL) {
-               ERR("cfg_parser: No memory left\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        memset(st, '\0', sizeof(*st));
@@ -904,22 +905,19 @@ int cfg_parse_str(void* param, cfg_parser_t* st, unsigned int flags)
                buf = val->s;
        } else if (flags & CFG_STR_SHMMEM) {
                if ((buf = shm_malloc(t.val.len + 1)) == NULL) {
-                       ERR("%s:%d:%d: Out of shared memory\n", st->file,
-                               t.start.line, t.start.col);
+                       SHM_MEM_ERROR;
                        return -1;
                }
                if (val->s) shm_free(val->s);
        } else if (flags & CFG_STR_MALLOC) {
                if ((buf = malloc(t.val.len + 1)) == NULL) {
-                       ERR("%s:%d:%d: Out of malloc memory\n", st->file,
-                               t.start.line, t.start.col);
+                       SYS_MEM_ERROR;
                        return -1;
                }
                if (val->s) free(val->s);
        } else if (flags & CFG_STR_PKGMEM) {
                if ((buf = pkg_malloc(t.val.len + 1)) == NULL) {
-                       ERR("%s:%d:%d: Out of private memory\n", st->file,
-                               t.start.line, t.start.col);
+                       PKG_MEM_ERROR;
                        return -1;
                }
                if (val->s) pkg_free(val->s);
index 9acc536..bfa962b 100644 (file)
@@ -453,7 +453,7 @@ static void core_pwd(rpc_t* rpc, void* c)
        max_len = pathmax();
        cwd_buf = pkg_malloc(max_len);
        if (!cwd_buf) {
-               ERR("core_pwd: No memory left\n");
+               PKG_MEM_ERROR;
                rpc->fault(c, 500, "Server Ran Out of Memory");
                return;
        }
index 9273aa7..ee31f31 100644 (file)
@@ -114,14 +114,18 @@ int init_counters()
        grp_no = 0;
        cnt_id2record_size = CNT_ID2RECORD_SIZE;
        cnt_id2record = pkg_malloc(sizeof(*cnt_id2record) * cnt_id2record_size);
-       if (cnt_id2record == 0)
+       if (cnt_id2record == 0) {
+               PKG_MEM_ERROR;
                goto error;
+       }
        memset(cnt_id2record, 0, sizeof(*cnt_id2record) * cnt_id2record_size);
        grp_sorted_max_size = GRP_SORTED_SIZE;
        grp_sorted_crt_size = 0;
        grp_sorted = pkg_malloc(sizeof(*grp_sorted) * grp_sorted_max_size);
-       if (grp_sorted == 0)
+       if (grp_sorted == 0) {
+               PKG_MEM_ERROR;
                goto error;
+       }
        memset(grp_sorted, 0, sizeof(*grp_sorted) * grp_sorted_max_size);
        return 0;
 error:
@@ -205,8 +209,10 @@ int counters_prefork_init(int max_process_no)
           the final shm version (with max_process_no rows) */
        old = _cnts_vals;
        _cnts_vals = shm_malloc(size);
-       if (_cnts_vals == 0)
+       if (_cnts_vals == 0) {
+               SHM_MEM_ERROR;
                return -1;
+       }
        memset(_cnts_vals, 0, size);
        cnts_max_rows = max_process_no;
        /* copy prefork values into the newly shm array */
@@ -232,8 +238,10 @@ static struct grp_record* grp_hash_add(str* group)
        /* grp_rec copied at &g->u.data */
        g = pkg_malloc(sizeof(struct str_hash_entry) - sizeof(g->u.data) +
                                        sizeof(*grp_rec) + group->len + 1);
-       if (g == 0)
+       if (g == 0) {
+               PKG_MEM_ERROR;
                goto error;
+       }
        grp_rec = (struct grp_record*)&g->u.data[0];
        grp_rec->group.s = (char*)(grp_rec + 1);
        grp_rec->group.len = group->len;
@@ -330,8 +338,10 @@ static struct counter_record* cnt_hash_add(
        e = pkg_malloc(sizeof(struct str_hash_entry) - sizeof(e->u.data) +
                                        sizeof(*cnt_rec) + name->len + 1 + group->len + 1 +
                                        doc_len + 1);
-       if (e == 0)
+       if (e == 0) {
+               PKG_MEM_ERROR;
                goto error;
+       }
        cnt_rec = (struct counter_record*)&e->u.data[0];
        cnt_rec->group.s = (char*)(cnt_rec + 1);
        cnt_rec->group.len = group->len;
index e033b4e..5a1acb1 100644 (file)
@@ -57,7 +57,7 @@ struct lump* append_new_lump(struct lump** list, char* new_hdr,
 
        tmp=pkg_malloc(sizeof(struct lump));
        if (tmp==0){
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                return 0;
        }
                
@@ -83,7 +83,7 @@ struct lump* add_new_lump(struct lump** list, char* new_hdr,
 
        tmp=pkg_malloc(sizeof(struct lump));
        if (tmp==0){
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                return 0;
        }
                
@@ -108,7 +108,7 @@ struct lump* insert_new_lump(struct lump** list, char* new_hdr,
 
        tmp=pkg_malloc(sizeof(struct lump));
        if (tmp==0){
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                return 0;
        }
        memset(tmp,0,sizeof(struct lump));
@@ -133,7 +133,7 @@ struct lump* insert_new_lump_after( struct lump* after, char* new_hdr,
        tmp=pkg_malloc(sizeof(struct lump));
        if (tmp==0){
                ser_error=E_OUT_OF_MEM;
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                return 0;
        }
        memset(tmp,0,sizeof(struct lump));
@@ -158,7 +158,7 @@ struct lump* insert_new_lump_before( struct lump* before, char* new_hdr,
        tmp=pkg_malloc(sizeof(struct lump));
        if (tmp==0){
                ser_error=E_OUT_OF_MEM;
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                return 0;
        }
        memset(tmp,0,sizeof(struct lump));
@@ -183,7 +183,7 @@ struct lump* insert_subst_lump_after( struct lump* after, enum lump_subst subst,
        tmp=pkg_malloc(sizeof(struct lump));
        if (tmp==0){
                ser_error=E_OUT_OF_MEM;
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                return 0;
        }
        memset(tmp,0,sizeof(struct lump));
@@ -209,7 +209,7 @@ struct lump* insert_subst_lump_before(      struct lump* before,
        tmp=pkg_malloc(sizeof(struct lump));
        if (tmp==0){
                ser_error=E_OUT_OF_MEM;
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                return 0;
        }
        memset(tmp,0,sizeof(struct lump));
@@ -234,7 +234,7 @@ struct lump* insert_cond_lump_after( struct lump* after, enum lump_conditions c,
        tmp=pkg_malloc(sizeof(struct lump));
        if (tmp==0){
                ser_error=E_OUT_OF_MEM;
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                return 0;
        }
        memset(tmp,0,sizeof(struct lump));
@@ -260,7 +260,7 @@ struct lump* insert_cond_lump_before(       struct lump* before,
        tmp=pkg_malloc(sizeof(struct lump));
        if (tmp==0){
                ser_error=E_OUT_OF_MEM;
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                return 0;
        }
        memset(tmp,0,sizeof(struct lump));
@@ -303,7 +303,7 @@ struct lump* del_lump(struct sip_msg* msg, int offset, int len, enum _hdr_types_
        
        tmp=pkg_malloc(sizeof(struct lump));
        if (tmp==0){
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                return 0;
        }
        memset(tmp,0,sizeof(struct lump));
@@ -358,7 +358,7 @@ struct lump* anchor_lump(struct sip_msg* msg, int offset, int len, enum _hdr_typ
        tmp=pkg_malloc(sizeof(struct lump));
        if (tmp==0){
                ser_error=E_OUT_OF_MEM;
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                return 0;
        }
        memset(tmp,0,sizeof(struct lump));
@@ -436,7 +436,7 @@ struct lump* anchor_lump2(struct sip_msg* msg, int offset, int len, enum _hdr_ty
        tmp=pkg_malloc(sizeof(struct lump));
        if (tmp==0){
                ser_error=E_OUT_OF_MEM;
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                return 0;
        }
        memset(tmp,0,sizeof(struct lump));
@@ -535,7 +535,11 @@ static struct lump *dup_lump_list_r( struct lump *l,
        if (!l) { *error=0; return 0; }
        /* otherwise duplicate current element */
        new_lump=pkg_malloc(sizeof(struct lump));
-       if (!new_lump) { *error=1; return 0; }
+       if (!new_lump) {
+               PKG_MEM_ERROR;
+               *error=1;
+               return 0;
+       }
 
        memcpy(new_lump, l, sizeof(struct lump));
        new_lump->flags=LUMPFLAG_DUPED;
@@ -750,7 +754,7 @@ int sr_hdr_add(sip_msg_t *msg, str *sname, str *sbody)
        h.len = sname->len + 2 + sbody->len + CRLF_LEN;
        h.s = (char*)pkg_malloc(h.len+1);
        if(h.s == 0) {
-               LM_ERR("no more pkg\n");
+               PKG_MEM_ERROR;
                return -1;
        }
        anchor = anchor_lump(msg, msg->last_header->name.s + msg->last_header->len
index 6b8ba8d..428654d 100644 (file)
@@ -56,7 +56,7 @@ struct lump_rpl** add_lump_rpl2(struct sip_msg *msg, char *s,
        lump = (struct lump_rpl*) pkg_malloc
                ( sizeof(struct lump_rpl) + ((flags&LUMP_RPL_NODUP)?0:len) );
        if (!lump) {
-               LM_ERR("no free pkg memory !\n");
+               PKG_MEM_ERROR;
                goto error;
        }
 
index e60be2c..8f3f4ae 100644 (file)
@@ -335,6 +335,7 @@ int init_dns_cache()
        }
        dns_cache_mem_used=shm_malloc(sizeof(*dns_cache_mem_used));
        if (dns_cache_mem_used==0){
+               SHM_MEM_ERROR;
                ret=E_OUT_OF_MEM;
                goto error;
        }
@@ -342,6 +343,7 @@ int init_dns_cache()
 
        dns_last_used_lst=shm_malloc(sizeof(*dns_last_used_lst));
        if (dns_last_used_lst==0){
+               SHM_MEM_ERROR;
                ret=E_OUT_OF_MEM;
                goto error;
        }
@@ -349,6 +351,7 @@ int init_dns_cache()
 
        dns_hash=shm_malloc(sizeof(struct dns_hash_head)*DNS_HASH_SIZE);
        if (dns_hash==0){
+               SHM_MEM_ERROR;
                ret=E_OUT_OF_MEM;
                goto error;
        }
@@ -370,6 +373,7 @@ int init_dns_cache()
 #ifdef DNS_WATCHDOG_SUPPORT
        dns_servers_up=shm_malloc(sizeof(atomic_t));
        if (dns_servers_up==0){
+               SHM_MEM_ERROR;
                ret=E_OUT_OF_MEM;
                goto error;
        }
@@ -416,6 +420,7 @@ int init_dns_cache_stats(int iproc_num)
 
        dns_cache_stats=shm_malloc(sizeof(*dns_cache_stats) * iproc_num);
        if (dns_cache_stats==0){
+               SHM_MEM_ERROR;
                return E_OUT_OF_MEM;
        }
        memset(dns_cache_stats, 0, sizeof(*dns_cache_stats) * iproc_num);
@@ -757,7 +762,7 @@ inline static struct dns_hash_entry* dns_cache_mk_bad_entry(str* name,
        size=sizeof(struct dns_hash_entry)+name->len-1+1;
        e=shm_malloc(size);
        if (e==0){
-               LM_ERR("out of memory\n");
+               SHM_MEM_ERROR;
                return 0;
        }
        memset(e, 0, size); /* init with 0*/
@@ -798,7 +803,7 @@ inline static struct dns_hash_entry* dns_cache_mk_ip_entry(str* name,
                        sizeof(struct dns_rr)+ ip->len;
        e=shm_malloc(size);
        if (e==0){
-               LM_ERR("out of memory\n");
+               SHM_MEM_ERROR;
                return 0;
        }
        memset(e, 0, size); /* init with 0*/
@@ -851,7 +856,7 @@ static struct dns_hash_entry* dns_cache_mk_srv_entry(str* name,
 
        e=shm_malloc(size);
        if (e==0){
-               LM_ERR("out of memory\n");
+               SHM_MEM_ERROR;
                return 0;
        }
        memset(e, 0, size); /* init with 0*/
@@ -1104,7 +1109,7 @@ inline static struct dns_hash_entry* dns_cache_mk_rd_entry(str* name, int type,
        size+=ROUND_POINTER(sizeof(struct dns_hash_entry)+name->len-1+1);
        e=shm_malloc(size);
        if (e==0){
-               LM_ERR("out of memory\n");
+               SHM_MEM_ERROR;
                return 0;
        }
        memset(e, 0, size); /* init with 0 */
@@ -1411,7 +1416,7 @@ found:
        for (r=0; r<no_records; r++){
                rec[r].e=shm_malloc(rec[r].size);
                if (rec[r].e==0){
-                       LM_ERR("out of memory\n");
+                       SHM_MEM_ERROR;
                        goto error;
                }
                memset(rec[r].e, 0, rec[r].size); /* init with 0*/
@@ -3988,7 +3993,7 @@ static struct dns_hash_entry *dns_cache_clone_entry(struct dns_hash_entry *e,
 
        new=shm_malloc(rounded_size+rr_size+rdata_size);
        if (!new) {
-               LM_ERR("out of memory\n");
+               SHM_MEM_ERROR;
                return NULL;
        }
        memset(new, 0, rounded_size+rr_size+rdata_size);
index ff40c19..a534366 100644 (file)
@@ -82,7 +82,7 @@ int init_dst_set(void)
        /* sr_dst_max_branches - 1 : because of the default branch for r-uri, #0 in tm */
        branches = (branch_t*)pkg_malloc((sr_dst_max_branches-1)*sizeof(branch_t));
        if(branches==NULL) {
-               LM_ERR("not enough memory to initialize destination branches\n");
+               PKG_MEM_ERROR;
                return -1;
        }
        memset(branches, 0, (sr_dst_max_branches-1)*sizeof(branch_t));
@@ -602,7 +602,7 @@ int rewrite_uri(struct sip_msg* _m, str* _s)
        if(_m->new_uri.s==NULL || _m->new_uri.len<_s->len) {
                buf = (char*)pkg_malloc(_s->len + 1);
                if (!buf) {
-                       LM_ERR("No memory left to rewrite r-uri\n");
+                       PKG_MEM_ERROR;
                        return -1;
                }
        }
index a2a4696..5259c34 100644 (file)
@@ -165,6 +165,7 @@ static int init_blst_callback_lst(struct blst_callbacks_lst*  cb_lst, int max)
        cb_lst->last_idx=0;
        cb_lst->hooks=pkg_malloc(cb_lst->max_hooks*sizeof(struct blacklist_hook));
        if (cb_lst->hooks==0)
+               PKG_MEM_ERROR;
                goto error;
        memset(cb_lst->hooks, 0, cb_lst->max_hooks*sizeof(struct blacklist_hook));
        return 0;
@@ -429,6 +430,7 @@ int init_dst_blacklist()
 #endif
        blst_mem_used=shm_malloc(sizeof(*blst_mem_used));
        if (blst_mem_used==0){
+               SHM_MEM_ERROR;
                ret=E_OUT_OF_MEM;
                goto error;
        }
@@ -436,6 +438,7 @@ int init_dst_blacklist()
        dst_blst_hash=shm_malloc(sizeof(struct dst_blst_lst_head) *
                                                                                        DST_BLST_HASH_SIZE);
        if (dst_blst_hash==0){
+               SHM_MEM_ERROR;
                ret=E_OUT_OF_MEM;
                goto error;
        }
@@ -511,6 +514,7 @@ int init_dst_blacklist_stats(int iproc_num)
 
        dst_blacklist_stats=shm_malloc(sizeof(*dst_blacklist_stats) * iproc_num);
        if (dst_blacklist_stats==0){
+               SHM_MEM_ERROR;
                return E_OUT_OF_MEM;
        }
        memset(dst_blacklist_stats, 0, sizeof(*dst_blacklist_stats) * iproc_num);
@@ -744,6 +748,7 @@ inline static int dst_blacklist_add_ip(unsigned char err_flags,
                        }
                        e=shm_malloc(size);
                        if (e==0){
+                               SHM_MEM_ERROR;
                                UNLOCK_BLST(hash);
                                ret=E_OUT_OF_MEM;
                                goto error;
index 51146b1..b41afb0 100644 (file)
@@ -218,7 +218,7 @@ void get_reply_status( str *status, struct sip_msg *reply, int code )
        status->len=phrase.len+3/*code*/+1/*space*/; 
        status->s=pkg_malloc(status->len+1/*ZT */);
        if (!status->s) {
-               LM_ERR("no mem\n");
+               PKG_MEM_ERROR;
                return;
        }
        status->s[3]=' ';
index c20f45f..589421c 100644 (file)
@@ -242,7 +242,7 @@ int register_flag(char* name, int pos)
        
        e=pkg_malloc(sizeof(struct flag_entry));
        if (e==0){
-               LM_ERR("memory allocation failure\n");
+               PKG_MEM_ERROR;
                return -3;
        }
        e->name.s=name;
index a6bf221..ecd50fe 100644 (file)
@@ -372,7 +372,7 @@ int register_check_self_func(check_self_f f)
        nf=(struct _check_self_func*)pkg_malloc(sizeof(struct _check_self_func));
        if(nf==0)
        {
-               LM_ERR("no more pkg\n");
+               PKG_MEM_ERROR;
                return -1;
        }
        nf->fself = f;
index 5d2d9fc..6740411 100644 (file)
@@ -474,8 +474,7 @@ int init_io_wait(io_wait_h* h, int max_fd, enum poll_types poll_method)
        /* common stuff, everybody has fd_hash */
        h->fd_hash=local_malloc(sizeof(*(h->fd_hash))*h->max_fd_no);
        if (h->fd_hash==0){
-               LM_CRIT("could not alloc fd hashtable (%ld bytes)\n",
-                                       (long)sizeof(*(h->fd_hash))*h->max_fd_no );
+               PKG_MEM_CRITICAL;
                goto error;
        }
        memset((void*)h->fd_hash, 0, sizeof(*(h->fd_hash))*h->max_fd_no);
@@ -493,8 +492,7 @@ int init_io_wait(io_wait_h* h, int max_fd, enum poll_types poll_method)
 #endif
                        h->fd_array=local_malloc(sizeof(*(h->fd_array))*h->max_fd_no);
                        if (h->fd_array==0){
-                               LM_CRIT("could not alloc fd array (%ld bytes)\n",
-                                               (long)sizeof(*(h->fd_hash))*h->max_fd_no);
+                               PKG_MEM_CRITICAL;
                                goto error;
                        }
                        memset((void*)h->fd_array, 0, sizeof(*(h->fd_array))*h->max_fd_no);
@@ -523,7 +521,7 @@ int init_io_wait(io_wait_h* h, int max_fd, enum poll_types poll_method)
                case POLL_EPOLL_ET:
                        h->ep_array=local_malloc(sizeof(*(h->ep_array))*h->max_fd_no);
                        if (h->ep_array==0){
-                               LM_CRIT("could not alloc epoll array\n");
+                               PKG_MEM_CRITICAL;
                                goto error;
                        }
                        memset((void*)h->ep_array, 0, sizeof(*(h->ep_array))*h->max_fd_no);
@@ -546,13 +544,13 @@ int init_io_wait(io_wait_h* h, int max_fd, enum poll_types poll_method)
                        h->kq_array_size=2 * h->max_fd_no + h->kq_changes_size;
                        h->kq_array=local_malloc(sizeof(*(h->kq_array))*h->kq_array_size);
                        if (h->kq_array==0){
-                               LM_CRIT("could not alloc kqueue event array\n");
+                               PKG_MEM_CRITICAL;
                                goto error;
                        }
                        h->kq_changes=local_malloc(sizeof(*(h->kq_changes))*
                                                                                h->kq_changes_size);
                        if (h->kq_changes==0){
-                               LM_CRIT("could not alloc kqueue changes array\n");
+                               PKG_MEM_CRITICAL;
                                goto error;
                        }
                        h->kq_nchanges=0;
index 3412af9..9989063 100644 (file)
@@ -51,7 +51,7 @@ struct net* mk_new_net(struct ip_addr* ip, struct ip_addr* mask)
        }
        n=(struct net*)pkg_malloc(sizeof(struct net));
        if (n==0){ 
-               LM_CRIT("memory allocation failure\n");
+               PKG_MEM_CRITICAL;
                goto error;
        }
        n->ip=*ip;
index 526ebf9..d15e021 100644 (file)
@@ -1533,7 +1533,7 @@ static int sr_kemi_hdr_append(sip_msg_t *msg, str *txt)
 
        hdr = (char*)pkg_malloc(txt->len);
        if(hdr==NULL) {
-               LM_ERR("no pkg memory left\n");
+               PKG_MEM_ERROR;
                return -1;
        }
        memcpy(hdr, txt->s, txt->len);
@@ -1593,7 +1593,7 @@ static int sr_kemi_hdr_append_after(sip_msg_t *msg, str *txt, str *hname)
 
        hdr = (char*)pkg_malloc(txt->len);
        if(hdr==NULL) {
-               LM_ERR("no pkg memory left\n");
+               PKG_MEM_ERROR;
                return -1;
        }
        memcpy(hdr, txt->s, txt->len);
@@ -1725,7 +1725,7 @@ static int sr_kemi_hdr_insert(sip_msg_t *msg, str *txt)
        LM_DBG("insert hf: %.*s\n", txt->len, txt->s);
        hdr = (char*)pkg_malloc(txt->len);
        if(hdr==NULL) {
-               LM_ERR("no pkg memory left\n");
+               PKG_MEM_ERROR;
                return -1;
        }
        memcpy(hdr, txt->s, txt->len);
@@ -1785,7 +1785,7 @@ static int sr_kemi_hdr_insert_before(sip_msg_t *msg, str *txt, str *hname)
 
        hdr = (char*)pkg_malloc(txt->len);
        if(hdr==NULL) {
-               LM_ERR("no pkg memory left\n");
+               PKG_MEM_ERROR;
                return -1;
        }
        memcpy(hdr, txt->s, txt->len);
@@ -2094,14 +2094,14 @@ int sr_kemi_cbname_list_init(void)
        if(_sr_kemi_cbname_list_size==NULL) {
                lock_destroy(_sr_kemi_cbname_lock);
                lock_dealloc(_sr_kemi_cbname_lock);
-               LM_ERR("no more shared memory\n");
+               SHM_MEM_ERROR;
                return -1;
        }
        *_sr_kemi_cbname_list_size = 0;
        _sr_kemi_cbname_list
                        = shm_malloc(KEMI_CBNAME_LIST_SIZE*sizeof(sr_kemi_cbname_t));
        if(_sr_kemi_cbname_list==NULL) {
-               LM_ERR("no more shared memory\n");
+               SHM_MEM_ERROR;
                shm_free(_sr_kemi_cbname_list_size);
                _sr_kemi_cbname_list_size = NULL;
                lock_destroy(_sr_kemi_cbname_lock);
index 145aa81..58864ea 100644 (file)
@@ -69,7 +69,7 @@ inline static gen_lock_set_t* lock_set_alloc(int n)
        gen_lock_set_t* ls;
        ls=(gen_lock_set_t*)shm_malloc(sizeof(gen_lock_set_t)+n*sizeof(gen_lock_t));
        if (ls==0){
-               LM_CRIT("could not allocate lock_set\n");
+               SHM_MEM_CRITICAL;
        }else{
                ls->locks=(gen_lock_t*)((char*)ls+sizeof(gen_lock_set_t));
                ls->size=n;
@@ -90,10 +90,12 @@ inline static gen_lock_set_t* lock_set_alloc(int n)
 {
        gen_lock_set_t* ls;
        ls=(gen_lock_set_t*)shm_malloc(sizeof(gen_lock_set_t));
-       if (ls){
+       if (ls==0){
+               SHM_MEM_CRITICAL;
+       }else{
                ls->size=n;
                ls->semid=-1;
-       };
+       }
        return ls;
 }
 
index fc267b0..aced1d2 100644 (file)
@@ -101,7 +101,7 @@ rec_lock_set_t* rec_lock_set_alloc(int n)
        rec_lock_set_t* ls;
        ls=(rec_lock_set_t*)shm_malloc(sizeof(rec_lock_set_t)+n*sizeof(rec_lock_t));
        if (ls==0){
-               LM_CRIT("could not allocate rec_lock_set\n");
+               SHM_MEM_CRITICAL;
        }else{
                ls->locks=(rec_lock_t*)((char*)ls+sizeof(rec_lock_set_t));
                ls->size=n;
index 9c8a953..f90237b 100644 (file)
@@ -211,7 +211,7 @@ int fixup_regexp_null(void** param, int param_no)
        if (param_no != 1)
                return E_UNSPEC;
        if ((re=pkg_malloc(sizeof(*re))) ==0) {
-               ERR("No memory left\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        if (regcomp(&re->regex, *param,
@@ -277,7 +277,7 @@ int fixup_pvar_all(void** param, int param_no)
                /* not a pvs id */
                goto error;
        if ((pvs_f=pkg_malloc(sizeof(*pvs_f))) == 0) {
-               ERR("No memory left\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        if (pv_parse_spec2(&name, &pvs_f->pvs, 1) == 0)
index 851a5ce..72ad2fb 100644 (file)
@@ -61,7 +61,7 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
        len = strlen(regex);
        reg = pkg_malloc(len + 4 + 1);
        if (reg == 0) {
-               LM_ERR("No memory left\n");
+               PKG_MEM_ERROR;
                return -1;
        }
        reg[0] = '^';
@@ -109,7 +109,7 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
                                                case PARAM_STRING:
                                                        *((char**)ptr) = pkg_malloc(strlen((char*)val2)+1);
                                                        if (!*((char**)ptr)) {
-                                                               LM_ERR("No memory left\n");
+                                                               PKG_MEM_ERROR;
                                                                regfree(&preg);
                                                                pkg_free(reg);
                                                                return -1;
@@ -120,7 +120,7 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
                                                case PARAM_STR:
                                                        ((str*)ptr)->s = pkg_malloc(((str*)val2)->len+1);
                                                        if (!((str*)ptr)->s) {
-                                                               LM_ERR("No memory left\n");
+                                                               PKG_MEM_ERROR;
                                                                regfree(&preg);
                                                                pkg_free(reg);
                                                                return -1;
index 08e518a..3bb0dd7 100644 (file)
@@ -332,7 +332,7 @@ char* received_builder(struct sip_msg *msg, unsigned int *received_len)
        buf=pkg_malloc(sizeof(char)*MAX_RECEIVED_SIZE);
        if (buf==0){
                ser_error=E_OUT_OF_MEM;
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                return 0;
        }
        memcpy(buf, RECEIVED, RECEIVED_LEN);
@@ -365,7 +365,7 @@ char* rport_builder(struct sip_msg *msg, unsigned int *rport_len)
        buf=pkg_malloc(sizeof(char)*(len+1));/* space for null term */
        if (buf==0){
                ser_error=E_OUT_OF_MEM;
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                return 0;
        }
        memcpy(buf, RPORT, RPORT_LEN);
@@ -397,7 +397,7 @@ char* id_builder(struct sip_msg* msg, unsigned int *id_len)
        buf=pkg_malloc(sizeof(char)*(len+1));/* place for ending \0 */
        if (buf==0){
                ser_error=E_OUT_OF_MEM;
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                return 0;
        }
        memcpy(buf, ID_PARAM, ID_PARAM_LEN);
@@ -440,7 +440,7 @@ char* clen_builder( struct sip_msg* msg, int *clen_len, int diff,
        buf=pkg_malloc(sizeof(char)*(len+1));
        if (buf==0){
                ser_error=E_OUT_OF_MEM;
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                return 0;
        }
        if (body_only) {
@@ -1734,7 +1734,7 @@ int get_boundary(struct sip_msg* msg, str* boundary)
                        if (boundary->s == NULL)
                        {
                                free_params(list);
-                               LM_ERR("no memory for boundary string\n");
+                               PKG_MEM_ERROR;
                                return -1;
                        }
                        *(boundary->s) = '-';
@@ -2087,7 +2087,7 @@ after_update_via1:
                path_buf.len=ROUTE_PREFIX_LEN+msg->path_vec.len+CRLF_LEN;
                path_buf.s=pkg_malloc(path_buf.len+1);
                if (unlikely(path_buf.s==0)){
-                       LM_ERR("out of memory\n");
+                       PKG_MEM_ERROR;
                        ser_error=E_OUT_OF_MEM;
                        goto error00;
                }
@@ -2187,7 +2187,10 @@ after_update_via1:
                new_buf=(char*)pkg_malloc(new_len+1);
        if (new_buf==0){
                ser_error=E_OUT_OF_MEM;
-               LM_ERR("out of memory\n");
+               if(unlikely(mode&BUILD_IN_SHM))
+                        SHM_MEM_ERROR;
+                else
+                        PKG_MEM_ERROR;
                goto error00;
        }
 
@@ -2289,7 +2292,7 @@ char * generate_res_buf_from_sip_res( struct sip_msg* msg,
        new_buf=(char*)pkg_malloc(new_len+1); /* +1 is for debugging
                                                                                         (\0 to print it )*/
        if (new_buf==0){
-               LM_ERR("out of mem\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        new_buf[new_len]=0; /* debug: print the message */
@@ -2446,7 +2449,7 @@ char * build_res_buf_from_sip_req( unsigned int code, str *text ,str *new_tag,
        buf = (char*) pkg_malloc( len+1 );
        if (!buf)
        {
-               LM_ERR("out of memory; needs %d\n",len);
+               PKG_MEM_ERROR;
                goto error01;
        }
 
@@ -2770,7 +2773,7 @@ char* via_builder(unsigned int *len, sip_msg_t *msg,
        line_buf=pkg_malloc( max_len );
        if (line_buf==0){
                ser_error=E_OUT_OF_MEM;
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                return 0;
        }
 
@@ -2942,7 +2945,7 @@ char* create_via_hf(unsigned int *len,
                /* params so far + ';rport' + '\0' */
                via = (char*)pkg_malloc(extra_params.len+RPORT_LEN);
                if(via==0) {
-                       LM_ERR("building local rport via param failed\n");
+                       PKG_MEM_ERROR;
                        if (extra_params.s) pkg_free(extra_params.s);
                        return 0;
                }
@@ -2964,7 +2967,7 @@ char* create_via_hf(unsigned int *len,
                } else {
                        via = (char*)pkg_malloc(extra_params.len+slen+1);
                        if(via==0) {
-                               LM_ERR("building srvid param failed\n");
+                               PKG_MEM_ERROR;
                                if (extra_params.s) pkg_free(extra_params.s);
                                return 0;
                        }
@@ -2988,7 +2991,7 @@ char* create_via_hf(unsigned int *len,
                if(xparams.len>0) {
                        via = (char*)pkg_malloc(extra_params.len+xparams.len+2);
                        if(via==0) {
-                               LM_ERR("building xavps params failed\n");
+                               PKG_MEM_ERROR;
                                if (extra_params.s) pkg_free(extra_params.s);
                                return 0;
                        }
@@ -3048,7 +3051,7 @@ char * build_only_headers( struct sip_msg* msg, int skip_first_line,
 
        new_buf = (char *)pkg_malloc(new_len+1);
        if (!new_buf) {
-               LM_ERR("Not enough memory\n");
+               PKG_MEM_ERROR;
                *error = -1;
                return 0;
        }
@@ -3098,7 +3101,7 @@ char * build_body( struct sip_msg* msg,
 
        new_buf = (char *)pkg_malloc(new_len+1);
        if (!new_buf) {
-               LM_ERR("Not enough memory\n");
+               PKG_MEM_ERROR;
                *error = -1;
                return 0;
        }
@@ -3158,7 +3161,7 @@ char * build_all( struct sip_msg* msg, int touch_clen,
 
        new_buf = (char *)pkg_malloc(new_len+1);
        if (!new_buf) {
-               LM_ERR("Not enough memory\n");
+               PKG_MEM_ERROR;
                *error = -1;
                return 0;
        }
index bfc15c8..ed75330 100644 (file)
@@ -101,7 +101,7 @@ static inline int add_alias(char* name, int len, unsigned short port,
        aliases=a;
        return 1;
 error:
-       LM_ERR("memory allocation error\n");
+       PKG_MEM_ERROR;
        if (a) pkg_free(a);
        return -1;
 }
index 16b00ff..022d575 100644 (file)
@@ -42,12 +42,13 @@ int init_nonsip_hooks()
        nonsip_hooks=pkg_malloc(nonsip_max_hooks*
                                                                        sizeof(struct nonsip_hook));
        if (nonsip_hooks==0){
+               PKG_MEM_ERROR;
                goto error;
        }
        memset(nonsip_hooks, 0, nonsip_max_hooks*sizeof(struct nonsip_hook));
        return 0;
 error:
-       LM_ERR("memory allocation failure\n");
+       PKG_MEM_ERROR;
        return -1;
 }
 
index 4c534ec..06b85dd 100644 (file)
@@ -187,7 +187,7 @@ int parse_contacts(str* _s, contact_t** _c)
                /* Allocate and clear contact structure */
                c = (contact_t*)pkg_malloc(sizeof(contact_t));
                if (c == 0) {
-                       LM_ERR("no memory left\n");
+                       PKG_MEM_ERROR;
                        goto error;
                }
                memset(c, 0, sizeof(contact_t));
index 603a5bf..af0cd39 100644 (file)
@@ -75,7 +75,7 @@ int parse_contact(struct hdr_field* _h)
 
        b = (contact_body_t*)pkg_malloc(sizeof(contact_body_t));
        if (b == 0) {
-               LM_ERR("no memory left\n");
+               PKG_MEM_ERROR;
                return -1;
        }
 
index 5bf3c2d..ccc62a6 100644 (file)
@@ -42,7 +42,7 @@ static inline int new_credentials(struct hdr_field* _h)
 
        b = (auth_body_t*)pkg_malloc(sizeof(auth_body_t));
        if (b == 0) {
-               LM_ERR("no memory left\n");
+               PKG_MEM_ERROR;
                return -1;
        }
 
index 03610dc..281c8ad 100644 (file)
@@ -115,7 +115,7 @@ char* get_hdr_field(char* const buf, char* const end, struct hdr_field* const hd
                        via_cnt++;
                        vb=pkg_malloc(sizeof(struct via_body));
                        if (vb==0){
-                               ERR("out of memory\n");
+                               PKG_MEM_ERROR;
                                goto error;
                        }
                        memset(vb,0,sizeof(struct via_body));
@@ -134,7 +134,7 @@ char* get_hdr_field(char* const buf, char* const end, struct hdr_field* const hd
                case HDR_CSEQ_T:
                        cseq_b=pkg_malloc(sizeof(struct cseq_body));
                        if (cseq_b==0){
-                               ERR("out of memory\n");
+                               PKG_MEM_ERROR;
                                goto error;
                        }
                        memset(cseq_b, 0, sizeof(struct cseq_body));
@@ -154,7 +154,7 @@ char* get_hdr_field(char* const buf, char* const end, struct hdr_field* const hd
                case HDR_TO_T:
                        to_b=pkg_malloc(sizeof(struct to_body));
                        if (to_b==0){
-                               ERR("out of memory\n");
+                               PKG_MEM_ERROR;
                                goto error;
                        }
                        memset(to_b, 0, sizeof(struct to_body));
@@ -324,8 +324,8 @@ int parse_headers(struct sip_msg* const msg, const hdr_flags_t flags, const int
                prefetch_loc_r(tmp+64, 1);
                hf=pkg_malloc(sizeof(struct hdr_field));
                if (unlikely(hf==0)){
+                       PKG_MEM_ERROR;
                        ser_error=E_OUT_OF_MEM;
-                       ERR("memory allocation error\n");
                        goto error;
                }
                memset(hf,0, sizeof(struct hdr_field));
@@ -751,7 +751,7 @@ int set_dst_uri(struct sip_msg* const msg, const str* const uri)
        } else {
                ptr = (char*)pkg_malloc(uri->len);
                if (!ptr) {
-                       ERR("Not enough memory\n");
+                       PKG_MEM_ERROR;
                        return -1;
                }
 
@@ -790,7 +790,7 @@ int set_path_vector(struct sip_msg* msg, str* path)
        } else {
                ptr = (char*)pkg_malloc(path->len);
                if (!ptr) {
-                       ERR("not enough pkg memory\n");
+                       PKG_MEM_ERROR;
                        return -1;
                }
 
@@ -830,7 +830,7 @@ int set_instance(struct sip_msg* msg, str* instance)
        } else {
                ptr = (char*)pkg_malloc(instance->len);
                if (!ptr) {
-                       ERR("not enough pkg memory for instance\n");
+                       PKG_MEM_ERROR;
                        return -1;
                }
                memcpy(ptr, instance->s, instance->len);
@@ -869,7 +869,7 @@ int set_ruid(struct sip_msg* msg, str* ruid)
        } else {
                ptr = (char*)pkg_malloc(ruid->len);
                if (!ptr) {
-                       ERR("not enough pkg memory for ruid\n");
+                       PKG_MEM_ERROR;
                        return -1;
                }
                memcpy(ptr, ruid->s, ruid->len);
@@ -908,7 +908,7 @@ int set_ua(struct sip_msg* msg, str* location_ua)
        } else {
                ptr = (char*)pkg_malloc(location_ua->len);
                if (!ptr) {
-                       ERR("not enough pkg memory for location_ua\n");
+                       PKG_MEM_ERROR;
                        return -1;
                }
                memcpy(ptr, location_ua->s, location_ua->len);
index 5779ba2..3516a19 100644 (file)
@@ -284,7 +284,7 @@ static char *parse_to_param(char *const buffer, const char *const end,
                                                param = (struct to_param *)pkg_malloc(
                                                                sizeof(struct to_param));
                                                if(!param) {
-                                                       LM_ERR("out of memory\n");
+                                                       PKG_MEM_ERROR;
                                                        goto error;
                                                }
                                                memset(param, 0, sizeof(struct to_param));
index fe127be..3b04975 100644 (file)
@@ -56,7 +56,7 @@ int parse_allow_header(struct hdr_field* _hf)
 
        ab = (struct allow_body*)pkg_malloc(sizeof(struct allow_body));
        if (ab == 0) {
-               LM_ERR("out of pkg_memory\n");
+               PKG_MEM_ERROR;
                return -1;
        }
        memset(ab,'\0', sizeof(struct allow_body));
index 6528147..007217d 100644 (file)
@@ -469,7 +469,7 @@ int parse_accept_body(struct hdr_field* const hdr)
        /* copy and link the mime buffer into the message */
        hdr->parsed = (void*)pkg_malloc((nr_mimes+1)*sizeof(int));
        if (hdr->parsed==0) {
-               LM_ERR("no more pkg memory\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        memcpy(hdr->parsed,mimes,nr_mimes*sizeof(int));
@@ -541,7 +541,7 @@ int parse_accept_hdr(struct sip_msg* const msg)
        /* copy and link the mime buffer into the message */
        msg->accept->parsed = (void*)pkg_malloc((nr_mimes+1)*sizeof(int));
        if (msg->accept->parsed==0) {
-               LM_ERR("no more pkg memory\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        memcpy(msg->accept->parsed,mimes,nr_mimes*sizeof(int));
index aa93709..7fa5b6e 100644 (file)
@@ -174,7 +174,7 @@ int parse_date_header(struct sip_msg *msg)
 
        date_b=pkg_malloc(sizeof(*date_b));
        if (date_b==0){
-               LM_ERR("out of pkg memory\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        memset(date_b, 0, sizeof(*date_b));
index 686f7b4..26a68a2 100644 (file)
@@ -287,7 +287,7 @@ int parse_disposition( str *s, struct disposition *disp)
                                                new_p=(struct disposition_param*)pkg_malloc
                                                        (sizeof(struct disposition_param));
                                                if (new_p==0) {
-                                                       LM_ERR("no more pkg mem\n");
+                                                       PKG_MEM_ERROR;
                                                        goto error;
                                                }
                                                memset(new_p,0,sizeof(struct disposition_param));
@@ -385,7 +385,7 @@ int parse_content_disposition( struct sip_msg *msg )
        /* parse the body */
        disp = (struct disposition*)pkg_malloc(sizeof(struct disposition));
        if (disp==0) {
-               LM_ERR("no more pkg memory\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        memset(disp,0,sizeof(struct disposition));
index 4578087..249a8cb 100644 (file)
@@ -65,7 +65,7 @@ int parse_diversion_header(struct sip_msg *msg)
        /* first, get some memory */
        diversion_b = pkg_malloc(sizeof(struct to_body));
        if (diversion_b == 0) {
-               LM_ERR("out of pkg_memory\n");
+               PKG_MEM_ERROR;
                goto error;
        }
 
index 0d57762..dc482eb 100644 (file)
@@ -152,7 +152,7 @@ int parse_event(struct hdr_field* _h)
 
        e = (event_t*)pkg_malloc(sizeof(event_t));
        if (e == 0) {
-               LM_ERR("No memory left\n");
+               PKG_MEM_ERROR;
                return -1;
        }
 
index 0d505cb..ad87fbd 100644 (file)
@@ -110,7 +110,7 @@ int parse_expires(struct hdr_field* _h)
 
        e = (exp_body_t*)pkg_malloc(sizeof(exp_body_t));
        if (e == 0) {
-               LM_ERR("No pkg memory left\n");
+               PKG_MEM_ERROR;
                return -1;
        }
 
index e6b93ac..6d46f21 100644 (file)
@@ -256,7 +256,9 @@ error:
                        else *(prn+t)=(char)176; /* '°' */
                LOG(L_DBG, "parsed so far: %.*s\n", offset, ZSW(prn) );
                pkg_free( prn );
-       };
+       } else {
+               PKG_MEM_ERROR;
+       }
 error1:
        fl->type=SIP_INVALID;
        LOG(cfg_get(core, core_cfg, corelog), "parse_first_line: bad message (offset: %d)\n", offset);
index b429551..beb89cc 100644 (file)
@@ -62,7 +62,7 @@ int parse_from_header(struct sip_msg *msg)
        /* first, get some memory */
        from_b = pkg_malloc(sizeof(struct to_body));
        if(from_b == 0) {
-               LM_ERR("out of pkg_memory\n");
+               PKG_MEM_ERROR;
                goto error;
        }
 
index 1813739..8408cb4 100644 (file)
@@ -63,7 +63,7 @@ int movetomybuffer (char *pstart,
        for (phashend = pcur; !isendofhash(phashend, pend); phashend++);
 
        if (!(ib->hash.s=pkg_malloc(phashend-pstart))) {
-               LM_ERR("out of pkg memory\n");
+               PKG_MEM_ERROR;
                return -2;
        }
        ib->ballocated=1;
@@ -154,7 +154,7 @@ int parse_identity_header(struct sip_msg *msg)
 
        identity_b=pkg_malloc(sizeof(*identity_b));
        if (identity_b==0){
-               LM_ERR("out of pkg memory\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        memset(identity_b, 0, sizeof(*identity_b));
index 425b083..5111ad7 100644 (file)
@@ -333,7 +333,7 @@ int parse_identityinfo_header(struct sip_msg *msg)
 
        identityinfo_b=pkg_malloc(sizeof(*identityinfo_b));
        if (identityinfo_b==0){
-               LM_ERR("out of pkg memory\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        memset(identityinfo_b, 0, sizeof(*identityinfo_b));
index 336bf88..5af3993 100644 (file)
@@ -584,7 +584,7 @@ int parse_params2(
        while(1) {
                t = (param_t *)pkg_malloc(sizeof(param_t));
                if(t == 0) {
-                       LM_ERR("No memory left\n");
+                       PKG_MEM_ERROR;
                        goto error;
                }
 
@@ -768,7 +768,11 @@ static inline int do_duplicate_params(param_t **_n, param_t *_p, int _shm)
                        t = (param_t *)pkg_malloc(sizeof(param_t));
                }
                if(!t) {
-                       LM_ERR("No more memory (%d)\n", _shm);
+                       if (_shm) {
+                               SHM_MEM_ERROR;
+                       } else {
+                               PKG_MEM_ERROR;
+                       }
                        goto err;
                }
                memcpy(t, ptr, sizeof(param_t));
index c337169..4e4ebe3 100644 (file)
@@ -83,7 +83,7 @@ int parse_pai_ppi_body(char *buf, int len, p_id_body_t **body)
        *body = pkg_malloc(sizeof(p_id_body_t) + num_uri * sizeof(to_body_t));
        if (*body == NULL)
        {
-               LM_ERR("No pkg memory for pai/ppi body\n");
+               PKG_MEM_ERROR;
                return -1;
        }
        memset(*body, 0, sizeof(p_id_body_t));
index a8919e1..c2deb39 100644 (file)
@@ -58,7 +58,7 @@ int parse_refer_to_header( struct sip_msg *msg )
        /* first, get some memory */
        refer_to_b = pkg_malloc(sizeof(struct to_body));
        if (refer_to_b == 0) {
-               LM_ERR("out of pkg memory\n");
+               PKG_MEM_ERROR;
                goto error;
        }
 
index e343e7f..d7646ca 100644 (file)
@@ -54,7 +54,7 @@ int parse_require( struct sip_msg *msg)
 
                rb = (struct option_tag_body*)pkg_malloc(sizeof(struct option_tag_body));
                if (rb == 0) {
-                       LM_ERR("out of pkg_memory\n");
+                       PKG_MEM_ERROR;
                        return -1;
                }
 
index c9290e8..e667bd2 100644 (file)
@@ -57,7 +57,7 @@ int parse_rpid_header( struct sip_msg *msg )
        /* first, get some memory */
        rpid_b = pkg_malloc(sizeof(struct to_body));
        if (rpid_b == 0) {
-               LM_ERR("out of pkg_memory\n");
+               PKG_MEM_ERROR;
                goto error;
        }
 
index 36dda0a..a089b89 100644 (file)
@@ -67,7 +67,7 @@ static inline int do_parse_rr_body(char *buf, int len, rr_t **head)
                /* Allocate and clear rr structure */
                r = (rr_t*)pkg_malloc(sizeof(rr_t));
                if (!r) {
-                       LM_ERR("No memory left\n");
+                       PKG_MEM_ERROR;
                        goto error;
                }
                memset(r, 0, sizeof(rr_t));
@@ -291,7 +291,11 @@ static inline int do_duplicate_rr(rr_t** _new, rr_t* _r, int _shm)
                if (_shm) res = shm_malloc(sizeof(rr_t) + len);
                else res = pkg_malloc(sizeof(rr_t) + len);
                if (!res) {
-                       LM_ERR("No memory left\n");
+                       if (_shm) {
+                               SHM_MEM_ERROR;
+                       } else {
+                               PKG_MEM_ERROR;
+                       }
                        return -2;
                }
                memcpy(res, it, sizeof(rr_t));
@@ -409,10 +413,9 @@ int print_rr_body(struct hdr_field *iroute, str *oroute, int order,
 
        oroute->s=(char*)pkg_malloc(route_len);
 
-
        if(oroute->s==0)
        {
-               LM_ERR("no more pkg mem\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        cp = start = oroute->s;
index 5b34713..dd77e66 100644 (file)
@@ -84,7 +84,7 @@ int parse_sipifmatch(struct hdr_field* _h)
 
        e = (str*)pkg_malloc(sizeof(str));
        if (e == 0) {
-               LM_ERR("No memory left\n");
+               PKG_MEM_ERROR;
                return -1;
        }
 
index bc7e42e..f7bdc88 100644 (file)
@@ -137,7 +137,7 @@ int parse_subscription_state(struct hdr_field *h)
 
        ss = (subscription_state_t*)pkg_malloc(sizeof(*ss));
        if (!ss) {
-               ERR("No memory left\n");
+               PKG_MEM_ERROR;
                return -1;
        }
 
index a08c37d..4ca108c 100644 (file)
@@ -54,7 +54,7 @@ int parse_supported( struct sip_msg *msg)
 
                sb = (struct option_tag_body*)pkg_malloc(sizeof(struct option_tag_body));
                if (sb == 0) {
-                       LM_ERR("out of pkg_memory\n");
+                       PKG_MEM_ERROR;
                        return -1;
                }
 
index 318bb8e..8805fad 100644 (file)
@@ -2510,7 +2510,7 @@ main_via:
                                                        vb->params.s = param_start;
                                                param = pkg_malloc(sizeof(struct via_param));
                                                if(param == 0) {
-                                                       LM_ERR("mem. allocation error\n");
+                                                       PKG_MEM_ERROR;
                                                        goto error;
                                                }
                                                memset(param, 0, sizeof(struct via_param));
@@ -2691,7 +2691,7 @@ nextvia:
        }
        vb->next = pkg_malloc(sizeof(struct via_body));
        if(vb->next == 0) {
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        vb = vb->next;
index f922f1b..b4c9ffc 100644 (file)
@@ -50,7 +50,7 @@ static inline int new_sdp(struct sip_msg* _m)
 
        sdp = (sdp_info_t*)pkg_malloc(sizeof(sdp_info_t));
        if (sdp == NULL) {
-               LM_ERR("No memory left\n");
+               PKG_MEM_ERROR;
                return -1;
        }
        memset( sdp, 0, sizeof(sdp_info_t));
@@ -72,7 +72,7 @@ static inline sdp_session_cell_t *add_sdp_session(sdp_info_t* _sdp, int session_
        len = sizeof(sdp_session_cell_t);
        session = (sdp_session_cell_t*)pkg_malloc(len);
        if (session == NULL) {
-               LM_ERR("No memory left\n");
+               PKG_MEM_ERROR;
                return NULL;
        }
        memset( session, 0, len);
@@ -103,7 +103,7 @@ static inline sdp_stream_cell_t *add_sdp_stream(sdp_session_cell_t* _session, in
        len = sizeof(sdp_stream_cell_t);
        stream = (sdp_stream_cell_t*)pkg_malloc(len);
        if (stream == NULL) {
-               LM_ERR("No memory left\n");
+               PKG_MEM_ERROR;
                return NULL;
        }
        memset( stream, 0, len);
@@ -144,7 +144,7 @@ static inline sdp_payload_attr_t *add_sdp_payload(sdp_stream_cell_t* _stream, in
        len = sizeof(sdp_payload_attr_t);
        payload_attr = (sdp_payload_attr_t*)pkg_malloc(len);
        if (payload_attr == NULL) {
-               LM_ERR("No memory left\n");
+               PKG_MEM_ERROR;
                return NULL;
        }
        memset( payload_attr, 0, len);
@@ -188,7 +188,11 @@ static inline sdp_payload_attr_t** init_p_payload_attr(sdp_stream_cell_t* _strea
                return NULL;
        }
        if (_stream->p_payload_attr == NULL) {
-               LM_ERR("No memory left\n");
+               if (pkg == USE_PKG_MEM) {
+                       PKG_MEM_ERROR;
+               } else if (pkg == USE_SHM_MEM) {
+                       SHM_MEM_ERROR;
+               }
                return NULL;
        }
 
@@ -986,7 +990,7 @@ sdp_payload_attr_t * clone_sdp_payload_attr(sdp_payload_attr_t *attr)
                        attr->fmtp_string.len;
        clone_attr = (sdp_payload_attr_t*)shm_malloc(len);
        if (clone_attr == NULL) {
-               LM_ERR("no more shm mem (%d)\n",len);
+               SHM_MEM_ERROR;
                return NULL;
        }
        memset( clone_attr, 0, len);
@@ -1058,7 +1062,7 @@ sdp_stream_cell_t * clone_sdp_stream_cell(sdp_stream_cell_t *stream)
                        stream->rtcp_port.len;
        clone_stream = (sdp_stream_cell_t*)shm_malloc(len);
        if (clone_stream == NULL) {
-               LM_ERR("no more shm mem (%d)\n",len);
+               SHM_MEM_ERROR;
                return NULL;
        }
        memset( clone_stream, 0, len);
@@ -1188,7 +1192,7 @@ sdp_session_cell_t * clone_sdp_session_cell(sdp_session_cell_t *session)
                session->bw_width.len;
        clone_session = (sdp_session_cell_t*)shm_malloc(len);
        if (clone_session == NULL) {
-               LM_ERR("no more shm mem (%d)\n",len);
+               SHM_MEM_ERROR;
                return NULL;
        }
        memset( clone_session, 0, len);
@@ -1282,7 +1286,7 @@ sdp_info_t * clone_sdp_info(struct sip_msg* _m)
        len = sizeof(sdp_info_t);
        clone_sdp_info = (sdp_info_t*)shm_malloc(len);
        if (clone_sdp_info == NULL) {
-               LM_ERR("no more shm mem (%d)\n",len);
+               SHM_MEM_ERROR;
                return NULL;
        }
        LM_DBG("clone_sdp_info: %p\n", clone_sdp_info);
index 2562b33..8f189cf 100644 (file)
@@ -263,7 +263,7 @@ static inline sdp_ice_attr_t *add_sdp_ice(sdp_stream_cell_t* _stream)
        len = sizeof(sdp_ice_attr_t);
        ice_attr = (sdp_ice_attr_t *)pkg_malloc(len);
        if (ice_attr == NULL) {
-           LM_ERR("No memory left\n");
+           PKG_MEM_ERROR;
            return NULL;
        }
        memset( ice_attr, 0, len);
index d15e0f8..1ff3103 100644 (file)
@@ -57,7 +57,7 @@ int pp_subst_add(char *data)
        pr = (pp_subst_rule_t*)pkg_malloc(sizeof(pp_subst_rule_t));
        if(pr==NULL)
        {
-               LM_ERR("no more pkg\n");
+               PKG_MEM_ERROR;
                return -1;
        }
        memset(pr, 0, sizeof(pp_subst_rule_t));
index 06e400b..3550796 100644 (file)
@@ -175,7 +175,7 @@ static int hostent_cpy(struct hostent *dst, struct hostent* src)
        int ret;
        HOSTENT_CPY(dst, src, pkg_malloc, pkg_free);
 error:
-       LM_CRIT("memory allocation failure\n");
+       PKG_MEM_CRITICAL;
        return ret;
 }
 
@@ -185,7 +185,7 @@ static int hostent_shm_cpy(struct hostent *dst, struct hostent* src)
        int ret;
        HOSTENT_CPY(dst, src, shm_malloc, shm_free);
 error:
-       LM_CRIT("memory allocation failure\n");
+       SHM_MEM_CRITICAL;
        return ret;
 }
 
@@ -217,7 +217,7 @@ error:
        return 0;
 }
 
-
+/* FIXME - we should use the same error logic as in HOSTENT_CPY */
 #define MK_PROXY(name, port, protocol, p_malloc, p_free, he_cpy)               \
        do {                                                                                                                            \
                struct proxy_l* p;                                                                                              \
@@ -280,7 +280,7 @@ struct proxy_l* mk_proxy_from_ip(struct ip_addr* ip, unsigned short port,
 
        p=(struct proxy_l*) pkg_malloc(sizeof(struct proxy_l));
        if (p==0){
-               LM_CRIT("memory allocation failure\n");
+               PKG_MEM_CRITICAL;
                goto error;
        }
        memset(p,0,sizeof(struct proxy_l));
@@ -291,12 +291,14 @@ struct proxy_l* mk_proxy_from_ip(struct ip_addr* ip, unsigned short port,
        p->host.h_length=ip->len;
        p->host.h_addr_list=pkg_malloc(2*sizeof(char*));
        if (p->host.h_addr_list==0) {
+               PKG_MEM_ERROR;
                pkg_free(p);
                goto error;
        }
        p->host.h_addr_list[1]=0;
        p->host.h_addr_list[0]=pkg_malloc(ip->len+1);
        if (p->host.h_addr_list[0]==0){
+               PKG_MEM_ERROR;
                pkg_free(p->host.h_addr_list);
                pkg_free(p);
                goto error;
index bf84df4..5e764db 100644 (file)
@@ -113,7 +113,11 @@ int init_pt(int proc_no)
        process_lock = lock_alloc();
        process_lock = lock_init(process_lock);
        if (pt==0||process_count==0||process_lock==0){
-               LM_ERR("out of memory\n");
+#ifdef SHM_MEM
+               SHM_MEM_ERROR;
+#else
+               PKG_MEM_ERROR;
+#endif
                return -1;
        }
        memset(pt, 0, sizeof(struct process_table)*estimated_proc_no);
index 841b180..23d70ba 100644 (file)
@@ -236,7 +236,7 @@ int pv_table_add(pv_export_t *e)
        pvn = (pv_item_t*)pkg_malloc(sizeof(pv_item_t));
        if(pvn==0)
        {
-               LM_ERR("no more memory\n");
+               PKG_MEM_ERROR;
                return -1;
        }
        memset(pvn, 0, sizeof(pv_item_t));
@@ -347,7 +347,7 @@ pv_spec_t* pv_cache_add(str *name)
        pvn = (pv_cache_t*)pkg_malloc(sizeof(pv_cache_t) + name->len + 1);
        if(pvn==0)
        {
-               LM_ERR("no more memory\n");
+               PKG_MEM_ERROR;
                return NULL;
        }
        memset(pvn, 0, sizeof(pv_cache_t) + name->len + 1);
@@ -756,7 +756,7 @@ int pv_parse_index(pv_spec_p sp, str *in)
                nsp = (pv_spec_p)pkg_malloc(sizeof(pv_spec_t));
                if(nsp==NULL)
                {
-                       LM_ERR("no more memory\n");
+                       PKG_MEM_ERROR;
                        return -1;
                }
                s = pv_parse_spec(in, nsp);
@@ -1133,8 +1133,10 @@ int pv_parse_format(str *in, pv_elem_p *el)
        if(in->len == 0)
        {
                *el = pkg_malloc(sizeof(pv_elem_t));
-               if(*el == NULL)
+               if(*el == NULL) {
+                       PKG_MEM_ERROR;
                        goto error;
+               }
                memset(*el, 0, sizeof(pv_elem_t));
                (*el)->text = *in;
                return 0;
@@ -1148,8 +1150,10 @@ int pv_parse_format(str *in, pv_elem_p *el)
        {
                e0 = e;
                e = pkg_malloc(sizeof(pv_elem_t));
-               if(!e)
+               if(!e) {
+                       PKG_MEM_ERROR;
                        goto error;
+               }
                memset(e, 0, sizeof(pv_elem_t));
                n++;
                if(*el == NULL)
@@ -1244,7 +1248,7 @@ int pv_parse_avp_name(pv_spec_p sp, str *in)
                nsp = (pv_spec_p)pkg_malloc(sizeof(pv_spec_t));
                if(nsp==NULL)
                {
-                       LM_ERR("no more memory\n");
+                       PKG_MEM_ERROR;
                        return -1;
                }
                s = pv_parse_spec(in, nsp);
@@ -1515,7 +1519,7 @@ pvname_list_t* parse_pvname_list(str *in, unsigned int type)
                al = (pvname_list_t*)pkg_malloc(sizeof(pvname_list_t));
                if(al==NULL)
                {
-                       LM_ERR("no more memory!\n");
+                       PKG_MEM_ERROR;
                        goto error;
                }
                memset(al, 0, sizeof(pvname_list_t));
@@ -1646,7 +1650,7 @@ static inline trans_t* tr_new(void)
        t = (trans_t*)pkg_malloc(sizeof(trans_t));
        if(t == NULL)
        {
-               LM_ERR("no more private memory\n");
+               PKG_MEM_ERROR;
                return NULL;
        }
        memset(t, 0, sizeof(trans_t));
@@ -1875,7 +1879,7 @@ int tr_table_add(tr_export_t *e)
        trn = (tr_item_t*)pkg_malloc(sizeof(tr_item_t));
        if(trn==0)
        {
-               LM_ERR("no more memory\n");
+               PKG_MEM_ERROR;
                return -1;
        }
        memset(trn, 0, sizeof(tr_item_t));
@@ -2045,7 +2049,7 @@ int pv_init_buffer(void)
                (char**)pkg_malloc(_pv_print_buffer_slots*sizeof(char*));
        if(_pv_print_buffer==NULL)
        {
-               LM_ERR("cannot init PV print buffer slots\n");
+               PKG_MEM_ERROR;
                return -1;
        }
        memset(_pv_print_buffer, 0, _pv_print_buffer_slots*sizeof(char*));
@@ -2055,7 +2059,7 @@ int pv_init_buffer(void)
                        (char*)pkg_malloc(_pv_print_buffer_size*sizeof(char));
                if(_pv_print_buffer[i]==NULL)
                {
-                       LM_ERR("cannot init PV print buffer slot[%d]\n", i);
+                       PKG_MEM_ERROR;
                        return -1;
                }
        }
index b71ec63..4ce18d8 100644 (file)
@@ -272,7 +272,7 @@ found_re:
 
        /* compile the re */
        if ((regex=pkg_malloc(sizeof(regex_t)))==0){
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        c=*re_end; /* regcomp expects null terminated strings -- save */
@@ -291,7 +291,7 @@ found_re:
                                        ((rw_no)?(rw_no-1)*sizeof(struct replace_with):0));
                /* 1 replace_with structure is  already included in subst_expr */
        if (se==0){
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        memset((void*)se, 0, sizeof(struct subst_expr));
@@ -299,7 +299,7 @@ found_re:
        se->replacement.len=repl_end-repl;
        if (se->replacement.len > 0) {
                if ((se->replacement.s=pkg_malloc(se->replacement.len))==0){
-                       LM_ERR("out of memory\n");
+                       PKG_MEM_ERROR;
                        goto error;
                }
                /* start copying */
@@ -390,7 +390,7 @@ static int replace_build(const char* match, int nmatch, regmatch_t* pmatch,
        RBUF_APPEND(dest, p, end-p);
        rpl->len = dest - rbuf;
        if ((rpl->s = pkg_malloc(rpl->len)) == NULL) {
-               LM_ERR("Out of pkg memory\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        memcpy(rpl->s, rbuf, rpl->len);
@@ -427,7 +427,7 @@ struct replace_lst* subst_run(struct subst_expr* se, const char* input,
        /* no of () referenced + 1 for the whole string: pmatch[0] */
        pmatch=pkg_malloc(nmatch*sizeof(regmatch_t));
        if (pmatch==0){
-               LM_ERR("out of mem\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        eflags=0;
@@ -446,7 +446,7 @@ struct replace_lst* subst_run(struct subst_expr* se, const char* input,
                        }
                        *crt=pkg_malloc(sizeof(struct replace_lst));
                        if (*crt==0){
-                               LM_ERR("out of mem\n");
+                               PKG_MEM_ERROR;
                                goto error;
                        }
                        memset(*crt, 0, sizeof(struct replace_lst));
@@ -508,12 +508,12 @@ str* subst_str(const char *input, struct sip_msg* msg, struct subst_expr* se,
                len+=(int)(l->rpl.len)-l->size;
        res=pkg_malloc(sizeof(str));
        if (res==0){
-               LM_ERR("mem. allocation error\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        res->s=pkg_malloc(len+1); /* space for null termination */
        if (res->s==0){
-               LM_ERR("mem. allocation error (res->s)\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        res->s[len]=0;
index 6be8fde..182d649 100644 (file)
@@ -191,7 +191,7 @@ int receive_msg(char *buf, unsigned int len, struct receive_info *rcv_info)
 
        msg = pkg_malloc(sizeof(struct sip_msg));
        if(unlikely(msg == 0)) {
-               LM_ERR("no mem for sip_msg\n");
+               PKG_MEM_ERROR;
                goto error00;
        }
        msg_no++;
index 80020a9..8be12e3 100644 (file)
@@ -307,7 +307,7 @@ struct srv_rdata* dns_srv_parser( unsigned char* msg, unsigned char* end,
        /* alloc enought space for the struct + null terminated name */
        srv=local_malloc(sizeof(struct srv_rdata)-1+len+1);
        if (srv==0){
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        srv->priority=ntohs(priority);
@@ -394,7 +394,7 @@ struct naptr_rdata* dns_naptr_parser( unsigned char* msg, unsigned char* end,
        naptr=local_malloc(sizeof(struct naptr_rdata)+flags_len+services_len+
                                                regexp_len+len+1-1);
        if (naptr == 0){
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        naptr->order=ntohs(order);
@@ -439,7 +439,7 @@ struct cname_rdata* dns_cname_parser( unsigned char* msg, unsigned char* end,
        /* alloc sizeof struct + space for the null terminated name */
        cname=local_malloc(sizeof(struct cname_rdata)-1+len+1);
        if(cname==0){
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        cname->name_len=len;
@@ -463,7 +463,7 @@ struct a_rdata* dns_a_parser(unsigned char* rdata, unsigned char* eor)
        if (rdata+4>eor) goto error;
        a=(struct a_rdata*)local_malloc(sizeof(struct a_rdata));
        if (a==0){
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        memcpy(a->ip, rdata, 4);
@@ -483,7 +483,7 @@ struct aaaa_rdata* dns_aaaa_parser(unsigned char* rdata, unsigned char* eor)
        if (rdata+16>eor) goto error;
        aaaa=(struct aaaa_rdata*)local_malloc(sizeof(struct aaaa_rdata));
        if (aaaa==0){
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        memcpy(aaaa->ip6, rdata, 16);
@@ -534,7 +534,7 @@ static struct txt_rdata* dns_txt_parser(unsigned char* msg, unsigned char* end,
        txt=local_malloc(sizeof(struct txt_rdata) +(n-1)*sizeof(struct dns_cstr)+
                                                str_size);
        if(unlikely(txt==0)){
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        /* string table */
@@ -604,7 +604,7 @@ static struct ebl_rdata* dns_ebl_parser(unsigned char* msg, unsigned char* end,
        /* alloc sizeof struct + space for the 2 null-terminated strings */
        ebl=local_malloc(sizeof(struct ebl_rdata)-1+sep_len+1+apex_len+1);
        if (ebl==0){
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        ebl->position=rdata[0];
@@ -642,7 +642,7 @@ struct ptr_rdata* dns_ptr_parser( unsigned char* msg, unsigned char* end,
        /* alloc sizeof struct + space for the null terminated name */
        pname=local_malloc(sizeof(struct ptr_rdata)-1+len+1);
        if(pname==0){
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        pname->ptrdname_len=len;
@@ -836,7 +836,7 @@ again:
                rd=(struct rdata*) local_malloc(sizeof(struct rdata)+rec_name_len+
                                                                                1-1);
                if (rd==0){
-                       LM_ERR("out of memory\n");
+                       PKG_MEM_ERROR;
                        goto error;
                }
                rd->type=rtype;
@@ -974,7 +974,7 @@ again:
        if ((search_list_used==1)&&(fullname_rd!=0)) {
                rd=(struct rdata*) local_malloc(sizeof(struct rdata)+name_len+1-1);
                if (unlikely(rd==0)){
-                       LM_ERR("out of memory\n");
+                       PKG_MEM_ERROR;
                        goto error;
                }
                rd->type=T_CNAME;
@@ -988,7 +988,7 @@ again:
                rd->rdata=(void*)local_malloc(sizeof(struct cname_rdata)-1+
                                                                                head->name_len+1);
                if(unlikely(rd->rdata==0)){
-                       LM_ERR("out of memory\n");
+                       PKG_MEM_ERROR;
                        goto error_rd;
                }
                ((struct cname_rdata*)(rd->rdata))->name_len=fullname_rd->name_len;
index aa81400..4aa7f25 100644 (file)
@@ -123,7 +123,7 @@ static int route_add(struct route_list* rt, char* name, int i)
        
        e=pkg_malloc(sizeof(struct str_hash_entry));
        if (e==0){
-               LM_CRIT("out of memory\n");
+               PKG_MEM_CRITICAL;
                goto error;
        }
        LM_DBG("mapping routing block (%p)[%s] to %d\n", rt, name, i);
@@ -145,8 +145,7 @@ inline  static int init_rlist(char* r_name, struct route_list* rt,
 {
                rt->rlist=pkg_malloc(sizeof(struct action*)*n_entries);
                if (rt->rlist==0){ 
-                       LM_CRIT("failed to allocate \"%s\" route tables: " 
-                                       "out of memory\n", r_name); 
+                       PKG_MEM_CRITICAL;
                        goto error; 
                }
                memset(rt->rlist, 0 , sizeof(struct action*)*n_entries);
@@ -339,8 +338,10 @@ static int exp_optimize_left(struct expr* exp)
                                                rval_destroy(rval);
                                                pkg_free(rve);
                                                ret=1;
-                                       }else
+                                       }else{
+                                               PKG_MEM_ERROR;
                                                ret=-1;
+                                       }
                                        break;
                                case RV_AVP:
                                        exp->l.attr=pkg_malloc(sizeof(*exp->l.attr));
@@ -350,8 +351,10 @@ static int exp_optimize_left(struct expr* exp)
                                                rval_destroy(rval);
                                                pkg_free(rve);
                                                ret=1;
-                                       }else
+                                       }else{
+                                               PKG_MEM_ERROR;
                                                ret=-1;
+                                       }
                                        break;
                                case RV_PVAR:
                                        exp->l.param=pkg_malloc(sizeof(pv_spec_t));
@@ -361,8 +364,10 @@ static int exp_optimize_left(struct expr* exp)
                                                rval_destroy(rval);
                                                pkg_free(rve);
                                                ret=1;
-                                       }else
+                                       }else{
+                                               PKG_MEM_ERROR;
                                                ret=-1;
+                                       }
                                        break;
                                case RV_NONE:
                                        break;
@@ -417,8 +422,10 @@ static int exp_optimize_right(struct expr* exp)
                                                rval_destroy(rval);
                                                pkg_free(rve);
                                                ret=1;
-                                       }else
+                                       }else{
+                                               PKG_MEM_ERROR;
                                                ret=-1;
+                                       }
                                        break;
                                case RV_BEXPR:
                                        /* cannot be optimized further, is an exp_elem
@@ -436,8 +443,10 @@ static int exp_optimize_right(struct expr* exp)
                                                rval_destroy(rval);
                                                pkg_free(rve);
                                                ret=1;
-                                       }else
+                                       }else{
+                                               PKG_MEM_ERROR;
                                                ret=-1;
+                                       }
                                        break;
                                case RV_AVP:
                                        exp->r.attr=pkg_malloc(sizeof(*exp->l.attr));
@@ -447,8 +456,10 @@ static int exp_optimize_right(struct expr* exp)
                                                rval_destroy(rval);
                                                pkg_free(rve);
                                                ret=1;
-                                       }else
+                                       }else{
+                                               PKG_MEM_ERROR;
                                                ret=-1;
+                                       }
                                        break;
                                case RV_PVAR:
                                        exp->r.param=pkg_malloc(sizeof(pv_spec_t));
@@ -458,8 +469,10 @@ static int exp_optimize_right(struct expr* exp)
                                                rval_destroy(rval);
                                                pkg_free(rve);
                                                ret=1;
-                                       }else
+                                       }else{
+                                               PKG_MEM_ERROR;
                                                ret=-1;
+                                       }
                                        break;
                                case RV_NONE:
                                        ret=-1;
@@ -540,7 +553,7 @@ int fix_expr(struct expr* exp)
                                if (exp->r_type==STRING_ST){
                                        re=(regex_t*)pkg_malloc(sizeof(regex_t));
                                        if (re==0){
-                                               LM_CRIT("memory allocation failure\n");
+                                               PKG_MEM_CRITICAL;
                                                return E_OUT_OF_MEM;
                                        }
                                        if (regcomp(re, (char*) exp->r.param,
@@ -1341,7 +1354,7 @@ inline static int comp_str(int op, str* left, int rtype,
                                        /* we need to compile the RE on the fly */
                                        re=(regex_t*)pkg_malloc(sizeof(regex_t));
                                        if (re==0){
-                                               LM_CRIT("memory allocation failure\n");
+                                               PKG_MEM_CRITICAL;
                                                left->s[left->len] = backup;
                                                goto error;
                                        }
index 0bc677d..063e177 100644 (file)
@@ -78,7 +78,7 @@ struct expr* mk_exp(int op, struct expr* left, struct expr* right)
        e->r.expr=right;
        return e;
 error:
-       LM_CRIT("memory allocation failure\n");
+       PKG_MEM_CRITICAL;
        return 0;
 }
 
@@ -97,7 +97,7 @@ struct expr* mk_elem(int op, expr_l_type ltype, void* lparam,
        e->r.param=rparam;
        return e;
 error:
-       LM_CRIT("memory allocation failure\n");
+       PKG_MEM_CRITICAL;
        return 0;
 }
 
@@ -134,7 +134,7 @@ struct action* mk_action(enum action_type type, int count, ...)
        return a;
 
 error:
-       LM_CRIT("memory allocation failure\n");
+       PKG_MEM_CRITICAL;
        return 0;
 }
 
index cbcd2a9..55fddc6 100644 (file)
@@ -49,7 +49,12 @@ int init_rpcs(void)
        str_hash_init(&rpc_hash_table);
        rpc_sarray_max_size=RPC_SARRAY_SIZE;
        rpc_sarray=pkg_malloc(sizeof(*rpc_sarray)* rpc_sarray_max_size);
-       rpc_sarray_crt_size=0;
+       if (rpc_sarray) {
+               rpc_sarray_crt_size=0;
+       } else {
+               PKG_MEM_ERROR;
+               return -1;
+       }
        return 0;
 }
 
@@ -103,7 +108,7 @@ static int rpc_hash_add(struct rpc_export* rpc)
 #endif /* RPC_COPY_EXPORT */
        
        if (e==0){
-               ERR("out of memory\n");
+               PKG_MEM_ERROR;
                goto error;
        }
 #ifdef RPC_COPY_EXPORT
index fcb238d..a124b18 100644 (file)
@@ -227,6 +227,9 @@ struct rvalue* rval_new_empty(int extra_size)
                rv->flags=RV_RV_ALLOCED_F;
                rv->refcnt=1;
                rv->type=RV_NONE;
+       } else {
+               PKG_MEM_ERROR;
+               return 0;
        }
        return rv;
 }
@@ -1255,7 +1258,7 @@ int rval_get_str(struct run_act_ctx* h, struct sip_msg* msg,
                goto error;
        s->s=pkg_malloc(tmp.len+1/* 0 term */);
        if (unlikely(s->s==0)){
-               LM_ERR("memory allocation error\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        s->len=tmp.len;
@@ -2535,8 +2538,10 @@ struct rval_expr* mk_rval_expr_v(enum rval_type rv_type, void* val,
        int flags;
 
        rve=pkg_malloc(sizeof(*rve));
-       if (rve==0)
+       if (rve==0) {
+               PKG_MEM_ERROR;
                return 0;
+       }
        memset(rve, 0, sizeof(*rve));
        flags=0;
        switch(rv_type){
@@ -2548,7 +2553,7 @@ struct rval_expr* mk_rval_expr_v(enum rval_type rv_type, void* val,
                        v.s.s=pkg_malloc(s->len+1 /*0*/);
                        if (v.s.s==0){
                                pkg_free(rve);
-                               LM_ERR("memory allocation failure\n");
+                               PKG_MEM_ERROR;
                                return 0;
                        }
                        v.s.len=s->len;
@@ -2614,8 +2619,10 @@ struct rval_expr* mk_rval_expr1(enum rval_expr_op op, struct rval_expr* rve1,
                        return 0;
        }
        ret=pkg_malloc(sizeof(*ret));
-       if (ret==0)
+       if (ret==0) {
+               PKG_MEM_ERROR;
                return 0;
+       }
        memset(ret, 0, sizeof(*ret));
        ret->op=op;
        ret->left.rve=rve1;
@@ -2672,8 +2679,10 @@ struct rval_expr* mk_rval_expr2(enum rval_expr_op op, struct rval_expr* rve1,
                        return 0;
        }
        ret=pkg_malloc(sizeof(*ret));
-       if (ret==0)
+       if (ret==0) {
+               PKG_MEM_ERROR;
                return 0;
+       }
        memset(ret, 0, sizeof(*ret));
        ret->op=op;
        ret->left.rve=rve1;
@@ -3027,7 +3036,7 @@ static int fix_match_rve(struct rval_expr* rve)
                rv=0;
                re=pkg_malloc(sizeof(*re));
                if (re==0){
-                       LM_ERR("out of memory\n");
+                       PKG_MEM_ERROR;
                        goto error;
                }
                /* same flags as for expr. =~ (fix_expr()) */
index 52d3698..2f83608 100644 (file)
@@ -58,7 +58,7 @@ static inline int add_callback( struct script_cb **list,
 
        new_cb=pkg_malloc(sizeof(struct script_cb));
        if (new_cb==0) {
-               LM_CRIT("out of memory\n");
+               PKG_MEM_CRITICAL;
                return -1;
        }
        new_cb->cbf = f;
index 21ba7f8..e0483e6 100644 (file)
@@ -203,7 +203,7 @@ int parse_select (char** p, select_t** s)
        
        sel=(select_t*)pkg_malloc(sizeof(select_t));
        if (!sel) {
-               LM_ERR("no free memory\n");
+               PKG_MEM_ERROR;
                return -1;
        }
        memset(sel, 0, sizeof(select_t));
@@ -233,7 +233,7 @@ int shm_parse_select (char** p, select_t** s)
        
        sel=(select_t*)shm_malloc(sizeof(select_t));
        if (!sel) {
-               LM_ERR("no free shared memory\n");
+               SHM_MEM_ERROR;
                return -1;
        }
        if (w_parse_select(p, sel)<0) {
@@ -457,7 +457,7 @@ int register_select_table(select_row_t* mod_tab)
        select_table_t* t;
        t=(select_table_t*)pkg_malloc(sizeof(select_table_t));
        if (!t) {
-               LM_ERR("No memory for new select_table structure\n");
+               PKG_MEM_ERROR;
                return -1;
        }
 
index 481c80c..e6c994d 100644 (file)
@@ -69,8 +69,10 @@ static int allocate_buffer(int req_size) {
        int size=ALLOC_SIZE(req_size);
        
        if (buffer[active_buffer].b == NULL) {
-               if ((buffer[active_buffer].b=pkg_malloc(size))==NULL)
+               if ((buffer[active_buffer].b=pkg_malloc(size))==NULL) {
+                       PKG_MEM_ERROR;
                        return 0;
+               }
                buffer[active_buffer].size=size;
                buffer[active_buffer].offset=0;
                return 1;
index 5279af4..e69c7f7 100644 (file)
@@ -496,7 +496,7 @@ struct sip_msg*  sip_msg_shm_clone( struct sip_msg *org_msg, int *sip_msg_len,
        p=(char *)shm_malloc(len);
        if (!p)
        {
-               LM_ERR("cannot allocate memory\n" );
+               SHM_MEM_ERROR;
                return 0;
        }
        if (sip_msg_len)
@@ -986,7 +986,7 @@ int msg_lump_cloner(struct sip_msg *pkg_msg,
        p=(char *)shm_malloc(len);
        if (!p)
        {
-               LM_ERR("cannot allocate memory\n" );
+               SHM_MEM_ERROR;
                return -1;
        }
 
index 424c5d8..16704a6 100644 (file)
@@ -141,7 +141,7 @@ static int init_addr_info(struct addr_info* a,
        a->flags=flags;
        return 0;
 error:
-       LM_ERR("memory allocation error\n");
+       PKG_MEM_ERROR;
        return -1;
 }
 
@@ -160,7 +160,7 @@ static inline struct addr_info* new_addr_info(char* name,
        if (init_addr_info(al, name, gf)!=0) goto error;
        return al;
 error:
-       LM_ERR("memory allocation error\n");
+       PKG_MEM_ERROR;
        if (al){
                if (al->name.s) pkg_free(al->name.s);
                pkg_free(al);
@@ -285,7 +285,7 @@ static inline struct socket_info* new_sock_info(    char* name,
        }
        return si;
 error:
-       LM_ERR("memory allocation error\n");
+       PKG_MEM_ERROR;
        if (si) {
                if(si->name.s)
                        pkg_free(si->name.s);
@@ -419,7 +419,7 @@ static int fix_sock_str(struct socket_info* si)
        
        si->sock_str.s = pkg_malloc(len + 1);
        if (si->sock_str.s == NULL) {
-               LM_ERR("No memory left\n");
+               PKG_MEM_ERROR;
                return -1;
        }
        if (socketinfo2str(si->sock_str.s, &len, si, 0) < 0) {
@@ -436,7 +436,7 @@ static int fix_sock_str(struct socket_info* si)
 
                si->useinfo.sock_str.s = pkg_malloc(len + 1);
                if (si->useinfo.sock_str.s == NULL) {
-                       LM_ERR("No memory left\n");
+                       PKG_MEM_ERROR;
                        return -1;
                }
                if (socketinfo2str(si->useinfo.sock_str.s, &len, si, 1) < 0) {
@@ -716,6 +716,10 @@ static struct socket_info* new_sock2list(char* name, struct name_lst* addr_l,
        if (mcast!=0) {
                si->mcast.len=strlen(mcast);
                si->mcast.s=(char*)pkg_malloc(si->mcast.len+1);
+               if (si->mcast.s==0) {
+                       PKG_MEM_ERROR;
+                       return 0;
+               }
                strcpy(si->mcast.s, mcast);
                mcast = 0;
        }
@@ -1012,7 +1016,7 @@ static int build_iface_list(void)
        if(ifaces == NULL){
                if((ifaces = (struct idxlist*)pkg_malloc(MAX_IFACE_NO
                                                *sizeof(struct idxlist))) == NULL){
-                       LM_ERR("No more pkg memory\n");
+                       PKG_MEM_ERROR;
                        return -1;
                }
                memset(ifaces, 0, sizeof(struct idxlist)*MAX_IFACE_NO);
@@ -1071,7 +1075,7 @@ static int build_iface_list(void)
                        entry = (struct idx*)pkg_malloc(sizeof(struct idx));
                        if(entry == 0)
                        {
-                               LM_ERR("could not allocate memory\n");
+                               PKG_MEM_ERROR;
                                goto error;
                        }
 
@@ -1282,7 +1286,7 @@ static int fix_hostname(str* name, struct ip_addr* address, str* address_str,
                pkg_free(name->s);
                name->s=(char*)pkg_malloc(strlen(he->h_name)+1);
                if (name->s==0){
-                       LM_ERR("out of memory.\n");
+                       PKG_MEM_ERROR;
                        goto error;
                }
                name->len=strlen(he->h_name);
@@ -1300,7 +1304,7 @@ static int fix_hostname(str* name, struct ip_addr* address, str* address_str,
        if ((tmp=ip_addr2a(address))==0) goto error;
        address_str->s=pkg_malloc(strlen(tmp)+1);
        if (address_str->s==0){
-               LM_ERR("out of memory.\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        strncpy(address_str->s, tmp, strlen(tmp)+1);
@@ -1508,7 +1512,7 @@ static int fix_socket_list(struct socket_info **list, int* type_flags)
                }
                si->port_no_str.s=(char*)pkg_malloc(len+1);
                if (si->port_no_str.s==0){
-                       LM_ERR("out of memory.\n");
+                       PKG_MEM_ERROR;
                        goto error;
                }
                strncpy(si->port_no_str.s, tmp, len+1);
index 199a307..a39f283 100644 (file)
@@ -214,7 +214,7 @@ static int register_module(module_exports_t* e, char* path, void* handle)
 
        /* add module to the list */
        if ((mod=pkg_malloc(sizeof(struct sr_module)))==0){
-               LM_ERR("memory allocation failure\n");
+               PKG_MEM_ERROR;
                ret=E_OUT_OF_MEM;
                goto error;
        }
@@ -231,6 +231,11 @@ static int register_module(module_exports_t* e, char* path, void* handle)
                for (n=0; e->cmds[n].name; n++);
        }
        mod->exports.cmds = pkg_malloc(sizeof(ksr_cmd_export_t)*(n+1));
+       if (mod->exports.cmds==0) {
+               PKG_MEM_ERROR;
+               ret=E_OUT_OF_MEM;
+               goto error;
+       }
        memset(mod->exports.cmds, 0, sizeof(ksr_cmd_export_t)*(n+1));
        for (i=0; i < n; i++) {
                mod->exports.cmds[i].name = e->cmds[i].name;
@@ -410,7 +415,10 @@ int load_module(char* mod_path)
                                /* try path <MODS_DIR>/<modname>.so */
                                path = (char*)pkg_malloc(mdir_len + 1 /* "/" */ +
                                                                        modname.len + 3 /* ".so" */ + 1);
-                               if (path==0) goto error;
+                               if (path==0) {
+                                       PKG_MEM_ERROR;
+                                       goto error;
+                               }
                                memcpy(path, mdir, mdir_len);
                                len = mdir_len;
                                if (len != 0 && path[len - 1] != '/'){
@@ -431,7 +439,10 @@ int load_module(char* mod_path)
                                                mdir_len + 1 /* "/" */ +
                                                modname.len + 1 /* "/" */ +
                                                modname.len + 3 /* ".so" */ + 1);
-                                       if (path==0) goto error;
+                                       if (path==0) {
+                                               PKG_MEM_ERROR;
+                                               goto error;
+                                       }
                                        memcpy(path, mdir, mdir_len);
                                        len = mdir_len;
                                        if (len != 0 && path[len - 1] != '/') {
@@ -463,7 +474,10 @@ int load_module(char* mod_path)
                                        /* try path <MODS_DIR>/mod_path - K compat */
                                        path = (char*)pkg_malloc(mdir_len + 1 /* "/" */ +
                                                                        strlen(mod_path) + 1);
-                                       if (path==0) goto error;
+                                       if (path==0) {
+                                               PKG_MEM_ERROR;
+                                               goto error;
+                                       }
                                        memcpy(path, mdir, mdir_len);
                                        len = mdir_len;
                                        if (len != 0 && path[len - 1] != '/'){
@@ -776,8 +790,7 @@ int init_modules(void)
        mod_response_cbks=pkg_malloc(mod_response_cbk_no *
                                                                        sizeof(response_function));
        if (mod_response_cbks==0){
-               LM_ERR("memory allocation failure for %d response_f callbacks\n",
-                                       mod_response_cbk_no);
+               PKG_MEM_ERROR;
                return -1;
        }
        for (t=modules, i=0; t && (i<mod_response_cbk_no); t=t->next) {
@@ -925,7 +938,7 @@ int init_modules(void)
        mod_response_cbks=pkg_malloc(mod_response_cbk_no *
                                                                        sizeof(response_function));
        if (mod_response_cbks==0){
-               LM_ERR("memory allocation failure for %d response_f callbacks\n", mod_response_cbk_no);
+               PKG_MEM_ERROR;
                return -1;
        }
        for (t=modules, i=0; t && (i<mod_response_cbk_no); t=t->next)
@@ -1061,7 +1074,7 @@ int fix_param(int type, void** param)
 
        p = (fparam_t*)pkg_malloc(sizeof(fparam_t));
        if (!p) {
-               LM_ERR("No memory left\n");
+               PKG_MEM_ERROR;
                return E_OUT_OF_MEM;
        }
        memset(p, 0, sizeof(fparam_t));
@@ -1094,7 +1107,7 @@ int fix_param(int type, void** param)
                        break;
                case FPARAM_REGEX:
                        if ((p->v.regex = pkg_malloc(sizeof(regex_t))) == 0) {
-                               LM_ERR("No memory left\n");
+                               PKG_MEM_ERROR;
                                goto error;
                        }
                        if (regcomp(p->v.regex, *param,
@@ -1156,7 +1169,7 @@ int fix_param(int type, void** param)
                        }
                        p->v.pvs=pkg_malloc(sizeof(pv_spec_t));
                        if (p->v.pvs==0){
-                               LM_ERR("out of memory while parsing pv_spec_t\n");
+                               PKG_MEM_ERROR;
                                goto error;
                        }
                        if (pv_parse_spec2(&name, p->v.pvs, 1)==0){
index 0f1545a..83bb02c 100644 (file)
@@ -90,7 +90,7 @@ int init_stats(int nr_of_processes)
 
        global_stats = shm_malloc(nr_of_processes*sizeof(struct stats_s));
        if(!global_stats) {
-               LM_ERR("Out of memory\n");
+               SHM_MEM_ERROR;
                return -1;
        }
        stats_segments = nr_of_processes;
index fda76c9..a7b835d 100644 (file)
@@ -39,7 +39,7 @@ int str_append(str *orig, str *suffix, str *dest)
        dest->s = pkg_malloc(sizeof(char)*dest->len);
        if(dest->s==NULL)
        {
-               LM_ERR("memory allocation failure\n");
+               PKG_MEM_ERROR;
                return -1;
        }
        if(orig->len>0)
index 982593f..8c6589f 100644 (file)
@@ -58,6 +58,7 @@ inline static int str_hash_alloc(struct str_hash_table* ht, int size)
 {
        ht->table=(struct str_hash_head*)pkg_malloc(sizeof(struct str_hash_head)*size);
        if (ht->table==0)
+               PKG_MEM_ERROR;
                return -1;
        ht->size=size;
        return 0;
index 6aeffc2..08b08c1 100644 (file)
@@ -41,7 +41,10 @@ static struct switch_cond_table* mk_switch_cond_table(int n)
        sct=pkg_malloc(ROUND_INT(sizeof(*sct))+
                                        ROUND_POINTER(n*sizeof(sct->cond[0]))+
                                        n*sizeof(sct->jump[0]));
-       if (sct==0) return 0;
+       if (sct==0) {
+               PKG_MEM_ERROR;
+               return 0;
+       }
        sct->n=n;
        sct->cond=(int*)((char*)sct+ROUND_INT(sizeof(*sct)));
        sct->jump=(struct action**)
@@ -68,7 +71,10 @@ static struct switch_jmp_table* mk_switch_jmp_table(int jmp_size, int rest)
                        ROUND_POINTER(rest*sizeof(jt->rest.cond[0]))+
                        rest*sizeof(jt->rest.jump[0]);
        jt=pkg_malloc(size);
-       if (jt == 0) return 0;
+       if (jt == 0) {
+               PKG_MEM_ERROR;
+               return 0;
+       }
        memset(jt, 0, size);
        jt->tbl = (struct action**)((char*) jt + ROUND_POINTER(sizeof(*jt)));
        jt->rest.cond = (int*)
@@ -92,7 +98,10 @@ static struct match_cond_table* mk_match_cond_table(int n)
        mct=pkg_malloc(ROUND_POINTER(sizeof(*mct))+
                                        ROUND_POINTER(n*sizeof(mct->match[0]))+
                                        n*sizeof(mct->jump[0]));
-       if (mct==0) return 0;
+       if (mct==0) {
+               PKG_MEM_ERROR;
+               return 0;
+       }
        mct->n=n;
        mct->match=(struct match_str*)((char*)mct+ROUND_POINTER(sizeof(*mct)));
        mct->jump=(struct action**)
@@ -242,7 +251,7 @@ int fix_switch(struct action* t)
        cond=pkg_malloc(sizeof(cond[0])*n);
        jmp_bm=pkg_malloc(sizeof(jmp_bm[0])*n);
        if (cond==0 || jmp_bm==0){
-               LM_ERR("memory allocation failure\n");
+               PKG_MEM_ERROR;
                ret=E_OUT_OF_MEM;
                goto error;
        }
@@ -479,7 +488,7 @@ static int fix_match(struct action* t)
                        }
                        if (c->type==MATCH_RE){
                                if ((regex=pkg_malloc(sizeof(regex_t))) == 0){
-                                       LM_ERR("out of memory\n");
+                                       PKG_MEM_ERROR;
                                        ret=E_OUT_OF_MEM;
                                        goto error;
                                }
@@ -560,7 +569,7 @@ static int fix_match(struct action* t)
        match=pkg_malloc(sizeof(match[0])*n);
        jmp_bm=pkg_malloc(sizeof(jmp_bm[0])*n);
        if (match==0 || jmp_bm==0){
-               LM_ERR("memory allocation failure\n");
+               PKG_MEM_ERROR;
                ret=E_OUT_OF_MEM;
                goto error;
        }
index 212a3aa..815452f 100644 (file)
@@ -650,6 +650,7 @@ inline static int _wbufq_add(struct  tcp_connection* c, const char* data,
                wb_size=MAX_unsigned(cfg_get(tcp, tcp_cfg, wq_blk_size), size);
                wb=shm_malloc(sizeof(*wb)+wb_size-1);
                if (unlikely(wb==0))
+                       SHM_MEM_ERROR;
                        goto error;
                wb->b_size=wb_size;
                wb->next=0;
@@ -671,6 +672,7 @@ inline static int _wbufq_add(struct  tcp_connection* c, const char* data,
                        wb_size=MAX_unsigned(cfg_get(tcp, tcp_cfg, wq_blk_size), size);
                        wb=shm_malloc(sizeof(*wb)+wb_size-1);
                        if (unlikely(wb==0))
+                               SHM_MEM_ERROR;
                                goto error;
                        wb->b_size=wb_size;
                        wb->next=0;
@@ -730,6 +732,7 @@ inline static int _wbufq_insert(struct  tcp_connection* c, const char* data,
                /* create a size bytes block directly */
                wb=shm_malloc(sizeof(*wb)+size-1);
                if (unlikely(wb==0))
+                       SHM_MEM_ERROR;
                        goto error;
                wb->b_size=size;
                /* insert it */
@@ -1191,7 +1194,7 @@ struct tcp_connection* tcpconn_new(int sock, union sockaddr_union* su,
        rd_b_size=cfg_get(tcp, tcp_cfg, rd_buf_size);
        c=shm_malloc(sizeof(struct tcp_connection) + rd_b_size);
        if (c==0){
-               LM_ERR("mem. allocation failure\n");
+               SHM_MEM_ERROR;
                goto error;
        }
        memset(c, 0, sizeof(struct tcp_connection)); /* zero init (skip rd buf)*/
@@ -3323,7 +3326,7 @@ static int send_fd_queue_init(struct tcp_send_fd_q *q, unsigned int size)
 {
        q->data=pkg_malloc(size*sizeof(struct send_fd_info));
        if (q->data==0){
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                return -1;
        }
        q->crt=q->data;
@@ -4899,27 +4902,27 @@ int init_tcp()
        /* init globals */
        tcp_connections_no=shm_malloc(sizeof(int));
        if (tcp_connections_no==0){
-               LM_CRIT("could not alloc globals\n");
+               SHM_MEM_CRITICAL;
                goto error;
        }
        *tcp_connections_no=0;
        tls_connections_no=shm_malloc(sizeof(int));
        if (tls_connections_no==0){
-               LM_CRIT("could not alloc globals\n");
+               SHM_MEM_CRITICAL;
                goto error;
        }
        *tls_connections_no=0;
        if (INIT_TCP_STATS()!=0) goto error;
        connection_id=shm_malloc(sizeof(int));
        if (connection_id==0){
-               LM_CRIT("could not alloc globals\n");
+               SHM_MEM_CRITICAL;
                goto error;
        }
        *connection_id=1;
 #ifdef TCP_ASYNC
        tcp_total_wq=shm_malloc(sizeof(*tcp_total_wq));
        if (tcp_total_wq==0){
-               LM_CRIT("could not alloc globals\n");
+               SHM_MEM_CRITICAL;
                goto error;
        }
 #endif /* TCP_ASYNC */
@@ -4927,13 +4930,13 @@ int init_tcp()
        tcpconn_aliases_hash=(struct tcp_conn_alias**)
                        shm_malloc(TCP_ALIAS_HASH_SIZE* sizeof(struct tcp_conn_alias*));
        if (tcpconn_aliases_hash==0){
-               LM_CRIT("could not alloc address hashtable\n");
+               SHM_MEM_CRITICAL;
                goto error;
        }
        tcpconn_id_hash=(struct tcp_connection**)shm_malloc(TCP_ID_HASH_SIZE*
                                                                sizeof(struct tcp_connection*));
        if (tcpconn_id_hash==0){
-               LM_CRIT("could not alloc id hashtable\n");
+               SHM_MEM_CRITICAL;
                goto error;
        }
        /* init hashtables*/
@@ -5035,7 +5038,7 @@ int tcp_init_children()
        /* alloc the children array */
        tcp_children=pkg_malloc(sizeof(struct tcp_child)*tcp_children_no);
        if (tcp_children==0){
-                       LM_ERR("out of memory\n");
+                       PKG_MEM_ERROR;
                        goto error;
        }
        memset(tcp_children, 0, sizeof(struct tcp_child)*tcp_children_no);
index 641bdc7..afb1248 100644 (file)
@@ -1407,7 +1407,7 @@ int receive_tcp_msg(char* tcpbuf, unsigned int len,
 #ifdef DYN_BUF
        buf=pkg_malloc(blen+1);
        if (buf==0) {
-               LM_ERR("could not allocate receive buffer\n");
+               PKG_MEM_ERROR;
                return -1;
        }
 #else
@@ -1426,7 +1426,7 @@ int receive_tcp_msg(char* tcpbuf, unsigned int len,
                        free(buf);
                buf=malloc(blen+1);
                if (buf==0) {
-                       LM_ERR("could not allocate receive buffer\n");
+                       SYS_MEM_ERROR;
                        return -1;
                }
                bsize = blen;
index 0e0dc88..9823617 100644 (file)
@@ -226,18 +226,18 @@ int init_timer()
        timer_lst=pkg_malloc(sizeof(struct timer_lists));
 #endif
        if (ticks==0){
-               LM_CRIT("out of shared memory (ticks)\n");
+               SHM_MEM_CRITICAL;
                ret=E_OUT_OF_MEM;
                goto error;
        }
        if (timer_lst==0){
-               LM_CRIT("out of shared memory (timer_lst)\n");
+               SHM_MEM_CRITICAL;
                ret=E_OUT_OF_MEM;
                goto error;
        }
        running_timer=shm_malloc(sizeof(struct timer_ln*));
        if (running_timer==0){
-               LM_CRIT("out of memory (running_timer)\n");
+               SHM_MEM_CRITICAL;
                ret=E_OUT_OF_MEM;
                goto error;
        }
@@ -283,7 +283,7 @@ int init_timer()
        slow_timer_lists=shm_malloc(sizeof(struct timer_head)*SLOW_LISTS_NO);
        running_timer2=shm_malloc(sizeof(struct timer_ln*));
        if ((t_idx==0)||(s_idx==0) || (slow_timer_lists==0) ||(running_timer2==0)){
-               LM_ERR("out of shared memory (slow)\n");
+               SHM_MEM_ERROR;
                ret=E_OUT_OF_MEM;
                goto error;
        }
@@ -1011,7 +1011,7 @@ int register_timer(timer_function f, void* param, unsigned int interval)
 
        t=shm_malloc(sizeof(struct sr_timer));
        if (t==0){
-               LM_ERR("out of memory\n");
+               SHM_MEM_ERROR;
                goto error;
        }
        t->id=timer_id++;
index e5b080c..20c50e0 100644 (file)
@@ -307,7 +307,7 @@ int sr_wtimer_init(void)
                return 0;
        _sr_wtimer = (sr_wtimer_t *)pkg_malloc(sizeof(sr_wtimer_t));
        if(_sr_wtimer==NULL) {
-               LM_ERR("no more pkg memory\n");
+               PKG_MEM_ERROR;
                return -1;
        }
 
@@ -329,7 +329,7 @@ int sr_wtimer_add(timer_function* f, void* param, int interval)
 
        wt = (sr_wtimer_node_t*)pkg_malloc(sizeof(sr_wtimer_node_t));
        if(wt==NULL) {
-               LM_ERR("no more pkg memory\n");
+               PKG_MEM_ERROR;
                return -1;
        }
        memset(wt, 0, sizeof(sr_wtimer_node_t));
index 1a1d200..7017b85 100644 (file)
@@ -283,7 +283,7 @@ int udp_init(struct socket_info* sock_info)
 /*
        addr=(union sockaddr_union*)pkg_malloc(sizeof(union sockaddr_union));
        if (addr==0){
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                goto error;
        }
 */
@@ -435,7 +435,7 @@ int udp_rcv_loop()
 
        from=(union sockaddr_union*) pkg_malloc(sizeof(union sockaddr_union));
        if (from==0){
-               LM_ERR("out of memory\n");
+               PKG_MEM_ERROR;
                goto error;
        }
        memset(from, 0 , sizeof(union sockaddr_union));
@@ -452,7 +452,7 @@ int udp_rcv_loop()
 #ifdef DYN_BUF
                buf=pkg_malloc(BUF_SIZE+1);
                if (buf==0){
-                       LM_ERR("could not allocate receive buffer\n");
+                       PKG_MEM_ERROR;
                        goto error;
                }
 #endif
index fc08cad..82183e3 100644 (file)
@@ -89,7 +89,7 @@ int init_avps(void)
        def_glist = (avp_list_t*)shm_malloc(sizeof(avp_list_t));
        crt_glist = (avp_list_t**)shm_malloc(sizeof(avp_list_t*));
        if (!def_glist || !crt_glist) {
-               LM_ERR("No memory to allocate default global AVP list\n");
+               SHM_MEM_ERROR;
                return -1;
        }
        *def_glist = 0;
@@ -174,7 +174,7 @@ avp_t *create_avp (avp_flags_t flags, avp_name_t name, avp_value_t val)
 
        avp = (struct usr_avp*)shm_malloc( len );
        if (avp==0) {
-               LM_ERR("no more shm mem\n");
+               SHM_MEM_ERROR;
                return 0;
        }
 
@@ -757,13 +757,13 @@ int add_avp_galias(str *alias, int type, int_str avp_name)
 
        ga = (struct avp_galias*)pkg_malloc( sizeof(struct avp_galias) );
        if (ga==0) {
-               LM_ERR("no more pkg memory\n");
+               PKG_MEM_ERROR;
                goto error;
        }
 
        ga->alias.s = (char*)pkg_malloc( alias->len+1 );
        if (ga->alias.s==0) {
-               LM_ERR("no more pkg memory\n");
+               PKG_MEM_ERROR;
                goto error1;
        }
        memcpy( ga->alias.s, alias->s, alias->len);
@@ -774,7 +774,7 @@ int add_avp_galias(str *alias, int type, int_str avp_name)
        if (type&AVP_NAME_STR) {
                ga->avp.name.s.s = (char*)pkg_malloc( avp_name.s.len+1 );
                if (ga->avp.name.s.s==0) {
-                       LM_ERR("no more pkg memory\n");
+                       PKG_MEM_ERROR;
                        goto error2;
                }
                ga->avp.name.s.len = avp_name.s.len;
@@ -993,7 +993,7 @@ int parse_avp_ident( str *name, avp_ident_t* attr)
                if ((name->len > 2) && (name->s[0]=='/') && (name->s[name->len-1]=='/')) {
                        attr->name.re=pkg_malloc(sizeof(regex_t));
                        if (!attr->name.re) {
-                               BUG("No free memory to allocate AVP_NAME_RE regex\n");
+                               PKG_MEM_ERROR;
                                goto error;
                        }
                        name->s[name->len-1]=0;
index 9856b72..77842c9 100644 (file)
@@ -160,7 +160,7 @@ char* as_asciiz(str* s)
 
     r = (char*)pkg_malloc(s->len + 1);
     if (!r) {
-               ERR("Out of memory\n");
+                       PKG_MEM_ERROR;
                return 0;
     }
     memcpy(r, s->s, s->len);
@@ -240,7 +240,7 @@ char* get_abs_pathname(str* base, str* file)
                /* This is an absolute pathname, make a zero terminated
                 * copy and use it as it is */
                if ((res = pkg_malloc(file->len+1)) == NULL) {
-                       ERR("get_abs_pathname: No memory left (pkg_malloc failed)\n");
+                       PKG_MEM_ERROR;
                        return NULL;
                }
                memcpy(res, file->s, file->len);
@@ -251,7 +251,7 @@ char* get_abs_pathname(str* base, str* file)
                 */
                /* Make a copy, function dirname may modify the string */
                if ((buf = pkg_malloc(base->len+1)) == NULL) {
-                       ERR("get_abs_pathname: No memory left (pkg_malloc failed)\n");
+                       PKG_MEM_ERROR;
                        return NULL;
                }
                memcpy(buf, base->s, base->len);
@@ -260,7 +260,7 @@ char* get_abs_pathname(str* base, str* file)
 
                len = strlen(dir);
                if ((res = pkg_malloc(len + 1 + file->len + 1)) == NULL) {
-                       ERR("get_abs_pathname: No memory left (pkg_malloc failed)\n");
+                       PKG_MEM_ERROR;
                        pkg_free(buf);
                        return NULL;
                }
index 66797f9..2680cf7 100644 (file)
@@ -93,6 +93,7 @@ static sr_xavp_t *xavp_new_value(str *name, sr_xval_t *val)
                size += val->v.s.len + 1;
        avp = (sr_xavp_t*)shm_malloc(size);
        if(avp==NULL)
+               SHM_MEM_ERROR;
                return NULL;
        memset(avp, 0, size);
        avp->id = id;