[sr-dev] [kamailio] jsonrpc-c notification does not free shm memory (#296)

zxcpoiu notifications at github.com
Wed Aug 26 16:26:02 CEST 2015


oh, sorry for the chaos.

here it is:

#### bt_AFTER_patch.corefile

```
(gdb) frame 3
#3  0x00007fe5d724f9ea in free_pipe_cmd (cmd=0x7fe5dca4a1d0) at jsonrpc_io.c:551
551                     shm_free(cmd->method);
(gdb) l
546
547
548     void free_pipe_cmd(struct jsonrpc_pipe_cmd *cmd)
549     {
550             if (cmd->method)
551                     shm_free(cmd->method);
552             if (cmd->params)
553                     shm_free(cmd->params);
554             if (cmd->cb_route)
555                     shm_free(cmd->cb_route);
```


#### below is my current diff between patched jsonrpc_io.c and 4.3.1 stable ( jsonrpc_io.c.orig )

```
--- jsonrpc_io.c.orig   2015-07-20 21:16:25.000000000 +0800
+++ jsonrpc_io.c    2015-08-26 13:25:24.628835993 +0800
@@ -85,8 +85,7 @@

    if (!connect_servers(server_group))
    {
-       LM_ERR("failed to connect to any servers\n");
-       return -1;
+       LM_WARN("failed to connect to any servers\n");
    }

    event_dispatch();
@@ -163,7 +162,7 @@

    if (!payload) {
        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);

@@ -201,7 +200,7 @@

        if (timerfd == -1) {
            LM_ERR("Could not create timerfd.");
-           return;
+           goto error;
        }

        req->timerfd = timerfd;
@@ -215,7 +214,7 @@
        if (timerfd_settime(timerfd, 0, itime, NULL) == -1)
        {
            LM_ERR("Could not set timer.");
-           return;
+           goto error;
        }
        pkg_free(itime);
        struct event *timer_ev = pkg_malloc(sizeof(struct event));
@@ -223,7 +222,7 @@
        event_set(timer_ev, timerfd, EV_READ, timeout_cb, req);
        if(event_add(timer_ev, NULL) == -1) {
            LM_ERR("event_add failed while setting request timer (%s).", strerror(errno));
-           return;
+           goto error;
        }
        req->timer_ev = timer_ev;
    } else if (!sent) {
@@ -237,6 +236,10 @@

    pkg_free(ns);
    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)
@@ -338,6 +341,7 @@

        struct jsonrpc_server *server = pkg_malloc(sizeof(struct jsonrpc_server));
        CHECK_MALLOC(server);
+       memset(server, 0, sizeof(struct jsonrpc_server));
        char *h = pkg_malloc(strlen(host)+1);
        CHECK_MALLOC(h);

@@ -365,6 +369,7 @@

            selected_group = pkg_malloc(sizeof(struct jsonrpc_server_group));
            CHECK_MALLOC(selected_group);
+           memset(selected_group, 0, sizeof(struct jsonrpc_server_group));
            selected_group->priority = priority;
            selected_group->next_server = server;


```



---
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/296#issuecomment-135039373
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sip-router.org/pipermail/sr-dev/attachments/20150826/7010162f/attachment-0001.html>


More information about the sr-dev mailing list