Summary:ASTERISK-16179: Memory Leak : main/manager.c
Reporter:fantiyu (fantiyu)Labels:
Date Opened:2010-06-01 05:25:50Date Closed:2011-06-07 14:00:19
Versions:Frequency of
Description:found memory leak yesterday. asterisk-

main/mamager.c, line 3154, function: do_message:
m.headers[m.hdrcount++] = ast_strdupa(header_buf);

the memory alloced by ast_strdupa are never released, we must release those before the function returned.


iv changed the code, and its running better than before:

static int do_message(struct mansession *s)
struct message m = { 0 };
char header_buf[sizeof(s->session->inbuf)] = { '\0' };
int res;
unsigned int i;

for (;;) {
/* Check if any events are pending and do them if needed */
if (process_events(s))
res = -1;
goto done;
res = get_input(s, header_buf);
if (res == 0)
} else if (res > 0)
if (ast_strlen_zero(header_buf))
return process_message(s, &m) ? -1 : 0;
else if (m.hdrcount < (AST_MAX_MANHEADERS - 1))
m.headers[m.hdrcount++] = ast_strdupa(header_buf);
} else
goto done;
//bug fix: free any memory alloced by ast_strdupa()
for (i = 0; i < m.hdrcount; i++)
return res;
Comments:By: Paul Belanger (pabelanger) 2010-06-01 08:53:01

Marking as related to ASTERISK-16005, only because there is an existing patch there.  Please download and test it.

Also, for the future, attach patches to the tracker.  Do not paste them as comments.

By: David Woolley (davidw) 2010-06-01 10:43:35

Actually, he should attach it even now, as it might turn out not to be the same problem. The intellectual property rules for Asterisk don't allow the developers to look at code that is not attached, with a valid, approved, licence grant to Digium.  He also needs to use unified diff.

By: Tilghman Lesher (tilghman) 2010-06-01 11:29:19

ast_strdupa allocates space off the stack.  That memory is automatically released when the function returns.  This is not a memory leak.