Skip to content

Commit

Permalink
topos: free temporary sip msg structure when handling 100 replies
Browse files Browse the repository at this point in the history
- it can lead to memory leak, reported by Sergey Basov

(cherry picked from commit 5613130)
  • Loading branch information
miconda committed Apr 21, 2017
1 parent 5afe7c2 commit fa72189
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/modules/topos/topos_mod.c
Expand Up @@ -280,12 +280,14 @@ int tps_msg_received(void *data)
str *obuf;
char *nbuf = NULL;
int dialog;
int ret;

obuf = (str*)data;
memset(&msg, 0, sizeof(sip_msg_t));
msg.buf = obuf->s;
msg.len = obuf->len;

ret = 0;
if(tps_prepare_msg(&msg)!=0) {
goto done;
}
Expand All @@ -310,17 +312,22 @@ int tps_msg_received(void *data)
/* reply */
if(msg.first_line.u.reply.statuscode==100) {
/* nothing to do - it should be absorbed */
return 0;
goto done;
}
tps_response_received(&msg);
}

nbuf = tps_msg_update(&msg, (unsigned int*)&obuf->len);

if(nbuf==NULL) {
LM_ERR("not enough pkg memory for new message\n");
ret = -1;
goto done;
}
if(obuf->len>=BUF_SIZE) {
LM_ERR("new buffer overflow (%d)\n", obuf->len);
pkg_free(nbuf);
return -1;
ret = -1;
goto done;
}
memcpy(obuf->s, nbuf, obuf->len);
obuf->s[obuf->len] = '\0';
Expand All @@ -329,7 +336,7 @@ int tps_msg_received(void *data)
if(nbuf!=NULL)
pkg_free(nbuf);
free_sip_msg(&msg);
return 0;
return ret;
}

/**
Expand Down Expand Up @@ -368,7 +375,7 @@ int tps_msg_sent(void *data)
/* reply */
if(msg.first_line.u.reply.statuscode==100) {
/* nothing to do - it should be locally generated */
return 0;
goto done;
}
tps_response_sent(&msg);
}
Expand Down

0 comments on commit fa72189

Please sign in to comment.