[asterisk-dev] Query on Memory Management Guidelines
Grey Man
greyvoip at yahoo.com.au
Mon Jul 23 06:01:15 CDT 2007
Hi,
I've been working on a patch I need to make to app_dial.c and in order to make it reliable for my use and also in case it should be useful for general use at some future stage I've been attempting to follow the coding guidelines and existing code style as best I can. Unfortunately I am not a native C programmer so some mechanisms have taken a while to sink in (the macros in the linkedlist and ast_sched implementation alone were enough to stump me for two days).
My question is regarding memory management and initialisation of structs. Is the recommended way to intialise structs as below?
struct mystruct * mine;
mine = ast_calloc(1, sizeof(*mine));
/* do work */
ast_free(mine);
One test I did on my patch was to turn on the MALLOC_DEBUG flag and use "show memory summary app_dial.c" before and after a call. In doing so I was seeing an increase per call of approx. 64 bytes. As best as I could tell (and I could be very wrong so please excuse me if so) the problem was not down to my modifications but to line 1593 in app_dial.c:
struct ast_bridge_config config;
memset(&config,0,sizeof(struct ast_bridge_config));
I could not find anywhere this memory was being released and changing to the ast_calloc mechanism above seemed to remove the leak. Any advice or beatings would be appreciated.
Thanks,
Greyman.
____________________________________________________________________________________ Yahoo!7 Mail has just got even bigger and better with unlimited storage on all webmail accounts.
http://au.docs.yahoo.com/mail/unlimitedstorage.html
More information about the asterisk-dev
mailing list