Module: kamailio
Branch: master
Commit: 1f9366ab5978ee4aa8fd3cefea0393c94889c26e
URL:
https://github.com/kamailio/kamailio/commit/1f9366ab5978ee4aa8fd3cefea0393c…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2018-01-14T09:52:25+01:00
db2_ops: proper check for memory allocation pointer
- check result codes for registering script callbacks
---
Modified: src/modules/db2_ops/db2_ops.c
---
Diff:
https://github.com/kamailio/kamailio/commit/1f9366ab5978ee4aa8fd3cefea0393c…
Patch:
https://github.com/kamailio/kamailio/commit/1f9366ab5978ee4aa8fd3cefea0393c…
---
diff --git a/src/modules/db2_ops/db2_ops.c b/src/modules/db2_ops/db2_ops.c
index dca2c81a1c..433d5293fc 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;