Ver código fonte

jsonrpc-c: free pipe cmd for notifications

- fixes leak reported by GH#296
Daniel-Constantin Mierla 10 anos atrás
pai
commit
79459d3f87
1 arquivos alterados com 8 adições e 4 exclusões
  1. 8 4
      modules/jsonrpc-c/jsonrpc_io.c

+ 8 - 4
modules/jsonrpc-c/jsonrpc_io.c

@@ -165,7 +165,7 @@ void cmd_pipe_cb(int fd, short event, void *arg)
 
 
 	if (!payload) {
 	if (!payload) {
 		LM_ERR("Failed to build jsonrpc_request_t (method: %s, params: %s)\n", cmd->method, cmd->params);	
 		LM_ERR("Failed to build jsonrpc_request_t (method: %s, params: %s)\n", cmd->method, cmd->params);	
-		return;
+		goto error;
 	}
 	}
 	char *json = (char*)json_object_get_string(payload);
 	char *json = (char*)json_object_get_string(payload);
 
 
@@ -203,7 +203,7 @@ void cmd_pipe_cb(int fd, short event, void *arg)
 
 
 		if (timerfd == -1) {
 		if (timerfd == -1) {
 			LM_ERR("Could not create timerfd.");
 			LM_ERR("Could not create timerfd.");
-			return;
+			goto error;
 		}
 		}
 
 
 		req->timerfd = timerfd;
 		req->timerfd = timerfd;
@@ -217,7 +217,7 @@ void cmd_pipe_cb(int fd, short event, void *arg)
 		if (timerfd_settime(timerfd, 0, itime, NULL) == -1) 
 		if (timerfd_settime(timerfd, 0, itime, NULL) == -1) 
 		{
 		{
 			LM_ERR("Could not set timer.");
 			LM_ERR("Could not set timer.");
-			return;
+			goto error;
 		}
 		}
 		pkg_free(itime);
 		pkg_free(itime);
 		struct event *timer_ev = pkg_malloc(sizeof(struct event));
 		struct event *timer_ev = pkg_malloc(sizeof(struct event));
@@ -225,7 +225,7 @@ void cmd_pipe_cb(int fd, short event, void *arg)
 		event_set(timer_ev, timerfd, EV_READ, timeout_cb, req); 
 		event_set(timer_ev, timerfd, EV_READ, timeout_cb, req); 
 		if(event_add(timer_ev, NULL) == -1) {
 		if(event_add(timer_ev, NULL) == -1) {
 			LM_ERR("event_add failed while setting request timer (%s).", strerror(errno));
 			LM_ERR("event_add failed while setting request timer (%s).", strerror(errno));
-			return;
+			goto error;
 		}
 		}
 		req->timer_ev = timer_ev;
 		req->timer_ev = timer_ev;
 	} else if (!sent) {
 	} else if (!sent) {
@@ -239,6 +239,10 @@ void cmd_pipe_cb(int fd, short event, void *arg)
 
 
 	pkg_free(ns);
 	pkg_free(ns);
 	json_object_put(payload);
 	json_object_put(payload);
+	if (cmd->notify_only) free_pipe_cmd(cmd);
+error:
+	if (cmd->notify_only) free_pipe_cmd(cmd);
+	return;
 }
 }
 
 
 void socket_cb(int fd, short event, void *arg)
 void socket_cb(int fd, short event, void *arg)