Skip to content

Commit

Permalink
[proto_hep] fix extra chunks memory leak
Browse files Browse the repository at this point in the history
	Extra chunks (the ones that are not defined in the internal
hep structure) were not freed, causing a memory leak for each hep
packet that had such chunks.
  • Loading branch information
ionutrazvanionita committed Sep 28, 2016
1 parent 7d2ab2b commit 7190a2d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
22 changes: 22 additions & 0 deletions modules/proto_hep/hep.c
Expand Up @@ -779,3 +779,25 @@ int unpack_hepv3(char *buf, int len, struct hep_desc *h)
return 0;
}

void free_extra_chunks(struct hep_desc* h)
{
generic_chunk_t *it, *foo=NULL;
if (h == NULL)
return;

if (h->version < 3 || h->u.hepv3.chunk_list == NULL)
return;

for (it=h->u.hepv3.chunk_list; it; foo=it, it=it->next) {
if (foo) {
shm_free(foo->data);
shm_free(foo);
}
}

if (foo) {
shm_free(foo->data);
shm_free(foo);
}

}
1 change: 1 addition & 0 deletions modules/proto_hep/hep.h
Expand Up @@ -236,6 +236,7 @@ int pack_hep(union sockaddr_union* from_su, union sockaddr_union* to_su,
int unpack_hepv12(char *buf, int len, struct hep_desc* h);
int unpack_hepv3(char *buf, int len, struct hep_desc *h);
int unpack_hep(char *buf, int len, int version, struct hep_desc* h);
void free_extra_chunks(struct hep_desc* h);


typedef int (*pack_hep_t)(union sockaddr_union* from_su, union sockaddr_union* to_su,
Expand Down
5 changes: 4 additions & 1 deletion modules/proto_hep/proto_hep.c
Expand Up @@ -941,6 +941,8 @@ static inline int hep_handle_req(struct tcp_req *req,
receive_msg(msg_buf, msg_len, &local_rcv, ctx) <0)
LM_ERR("receive_msg failed \n");

free_extra_chunks(&hep_ctx->h);

if (!size && req != &hep_current_req) {
/* if we no longer need this tcp_req
* we can free it now */
Expand Down Expand Up @@ -1160,7 +1162,6 @@ static int hep_udp_read_req(struct socket_info *si, int* bytes_read)
#else
static char buf [BUF_SIZE+1];
#endif
char *tmp;
unsigned int fromlen;
str msg;

Expand Down Expand Up @@ -1281,6 +1282,8 @@ static int hep_udp_read_req(struct socket_info *si, int* bytes_read)
receive_msg( msg.s, msg.len, &ri, ctx);
}

free_extra_chunks(&hep_ctx->h);

return 0;

error_free_hep:
Expand Down

0 comments on commit 7190a2d

Please sign in to comment.