Module: kamailio
Branch: master
Commit: 3553ee0b4e2e973a742c5c73f43d848496959723
URL:
https://github.com/kamailio/kamailio/commit/3553ee0b4e2e973a742c5c73f43d848…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2022-04-25T11:39:10+02:00
janssonrpcc: free resources in case of errors
---
Modified: src/modules/janssonrpcc/janssonrpc_io.c
Modified: src/modules/janssonrpcc/janssonrpc_request.c
Modified: src/modules/janssonrpcc/janssonrpc_server.c
Modified: src/modules/janssonrpcc/janssonrpc_srv.c
---
Diff:
https://github.com/kamailio/kamailio/commit/3553ee0b4e2e973a742c5c73f43d848…
Patch:
https://github.com/kamailio/kamailio/commit/3553ee0b4e2e973a742c5c73f43d848…
---
diff --git a/src/modules/janssonrpcc/janssonrpc_io.c
b/src/modules/janssonrpcc/janssonrpc_io.c
index 5e9d01d004..830c2b9611 100644
--- a/src/modules/janssonrpcc/janssonrpc_io.c
+++ b/src/modules/janssonrpcc/janssonrpc_io.c
@@ -442,6 +442,7 @@ int jsonrpc_send(str conn, jsonrpc_request_t* req, bool notify_only)
if (sent) {
if (notify_only == true) { // free the request if using janssonrpc_notification
function
free_req_cmd(req->cmd);
+ req->cmd = NULL;
free_request(req);
} else {
struct timeval tv;
diff --git a/src/modules/janssonrpcc/janssonrpc_request.c
b/src/modules/janssonrpcc/janssonrpc_request.c
index ecd43c1476..758c56b61d 100644
--- a/src/modules/janssonrpcc/janssonrpc_request.c
+++ b/src/modules/janssonrpcc/janssonrpc_request.c
@@ -217,7 +217,7 @@ void retry_cb(int fd, short event, void* arg)
DEBUG("retrying request: id=%d\n", req->id);
- if(jsonrpc_send(req->cmd->conn, req, 0)<0) {
+ if(jsonrpc_send(req->cmd->conn, req, false)<0) {
goto error;
}
diff --git a/src/modules/janssonrpcc/janssonrpc_server.c
b/src/modules/janssonrpcc/janssonrpc_server.c
index 6c4b999b50..16365fe214 100644
--- a/src/modules/janssonrpcc/janssonrpc_server.c
+++ b/src/modules/janssonrpcc/janssonrpc_server.c
@@ -278,7 +278,7 @@ int jsonrpc_server_from_srv(str conn, str srv,
DBG("server %s\n", srv_record->name);
server = create_server();
- CHECK_MALLOC(server);
+ CHECK_MALLOC_GOTO(server, error);
shm_str_dup(&server->conn, &conn);
CHECK_MALLOC_GOTO(server->conn.s, error);
diff --git a/src/modules/janssonrpcc/janssonrpc_srv.c
b/src/modules/janssonrpcc/janssonrpc_srv.c
index 3ce7e28676..e29767ffa7 100644
--- a/src/modules/janssonrpcc/janssonrpc_srv.c
+++ b/src/modules/janssonrpcc/janssonrpc_srv.c
@@ -89,6 +89,7 @@ int refresh_srv(jsonrpc_srv_t* srv_obj)
continue;
srv_record = (struct srv_rdata*)l->rdata;
if (srv_record == NULL) {
+ free_rdata_list(head);
ERR("BUG: null rdata\n");
return -1;
}
@@ -109,16 +110,16 @@ int refresh_srv(jsonrpc_srv_t* srv_obj)
jsonrpc_server_group_t* cgroup = NULL;
for(cgroup=conn_group; cgroup!=NULL; cgroup=cgroup->next) {
new_server = create_server();
- CHECK_MALLOC(new_server);
+ CHECK_MALLOC_GOTO(new_server, errdup);
shm_str_dup(&new_server->conn, &cgroup->conn);
- CHECK_MALLOC(new_server->conn.s);
+ CHECK_MALLOC_GOTO(new_server->conn.s, errdup);
shm_str_dup(&new_server->addr, &name);
- CHECK_MALLOC(new_server->addr.s);
+ CHECK_MALLOC_GOTO(new_server->addr.s, errdup);
shm_str_dup(&new_server->srv, &srv);
- CHECK_MALLOC(new_server->srv.s);
+ CHECK_MALLOC_GOTO(new_server->srv.s, errdup);
new_server->port = srv_record->port;
new_server->priority = srv_record->priority;
@@ -129,6 +130,7 @@ int refresh_srv(jsonrpc_srv_t* srv_obj)
addto_server_list(new_server, &new_servers);
}
}
+ free_rdata_list(head);
if(iter <= 0) goto end;
@@ -204,6 +206,12 @@ int refresh_srv(jsonrpc_srv_t* srv_obj)
free_server_list(rm_servers);
return retval;
+
+errdup:
+ free_rdata_list(head);
+ free_server_list(new_servers);
+ free_server(new_server);
+ return -1;
}
void free_srv(jsonrpc_srv_t* srv)