From 1f9366ab5978ee4aa8fd3cefea0393c94889c26e Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Sun, 14 Jan 2018 09:52:25 +0100 Subject: [PATCH] db2_ops: proper check for memory allocation pointer - check result codes for registering script callbacks --- src/modules/db2_ops/db2_ops.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/modules/db2_ops/db2_ops.c b/src/modules/db2_ops/db2_ops.c index dca2c81a1cb..433d5293fc6 100644 --- a/src/modules/db2_ops/db2_ops.c +++ b/src/modules/db2_ops/db2_ops.c @@ -201,7 +201,7 @@ static int split_fields(char *part, int *n, struct xlstr **strs) { int i, res; char *c, *fld; - if(part==NULL || *part=='\0') + if(part==NULL || *part=='\0' || strs==NULL) return -1; *n = 0; @@ -213,7 +213,7 @@ static int split_fields(char *part, int *n, struct xlstr **strs) { (*n)++; } *strs = pkg_malloc( (*n)*sizeof(**strs)); - if (!strs) { + if (*strs==NULL) { ERR(MODULE_NAME": split_fields: not enough pkg memory\n"); return E_OUT_OF_MEM; } @@ -1043,12 +1043,27 @@ static int mod_init(void) { for (p=dbops_actions; p; p=p->next) { int res; res = init_action(p); - if (res < 0) + if (res < 0) { + pkg_free(xlbuf); + xlbuf = NULL; return res; + } } - register_script_cb(dbops_pre_script_cb, REQUEST_CB | ONREPLY_CB | PRE_SCRIPT_CB, 0); - register_script_cb(dbops_post_script_cb, REQUEST_CB | ONREPLY_CB | POST_SCRIPT_CB, 0); + if(register_script_cb(dbops_pre_script_cb, + REQUEST_CB | ONREPLY_CB | PRE_SCRIPT_CB, 0)<0) { + LM_ERR("failed to register pre script callback\n"); + pkg_free(xlbuf); + xlbuf = NULL; + return -1; + } + if(register_script_cb(dbops_post_script_cb, + REQUEST_CB | ONREPLY_CB | POST_SCRIPT_CB, 0)<0) { + LM_ERR("failed to register post script callback\n"); + pkg_free(xlbuf); + xlbuf = NULL; + return -1; + } register_select_table(sel_declaration); return 0;