dialog: free old outbound buffer inside SREV_NET_DATA_OUT callback
authorDaniel-Constantin Mierla <miconda@gmail.com>
Mon, 12 Aug 2019 09:18:08 +0000 (11:18 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Mon, 12 Aug 2019 09:18:08 +0000 (11:18 +0200)
src/modules/dialog/dlg_cseq.c

index 8986d0a..fd993b0 100644 (file)
@@ -364,6 +364,7 @@ int dlg_cseq_msg_sent(sr_event_param_t *evp)
        struct via_body *via;
        hdr_field_t *hfk = NULL;
        sr_cfgenv_t *cenv = NULL;
+       str nbuf = STR_NULL;
 
        obuf = (str*)evp->data;
        memset(&msg, 0, sizeof(sip_msg_t));
@@ -520,11 +521,13 @@ int dlg_cseq_msg_sent(sr_event_param_t *evp)
                }
        }
        /* replace old msg content */
-       obuf->s = pkg_malloc((tbuf_len+1)*sizeof(char));
-       if(obuf->s==NULL) {
+       nbuf.s = pkg_malloc((tbuf_len+1)*sizeof(char));
+       if(nbuf.s==NULL) {
                LM_ERR("not enough memory for new message\n");
                goto done;
        }
+       pkg_free(obuf->s);
+       obuf->s = nbuf.s;
        memcpy(obuf->s, tbuf, tbuf_len);
        obuf->s[tbuf_len] = 0;
        obuf->len = tbuf_len;