talloc, malloc and memory leaks

Holger Hans Peter Freyther hfreyther at sysmocom.de
Tue Jul 24 21:51:17 UTC 2012


this is not meant as an intensive review on memory allocations
in the PCU code. While browsing the code of the ready-to-send
method to select the next payload I noticed the code below:

RlcMacDownlink_t * mac_control_block = (RlcMacDownlink_t *)malloc(sizeof(RlcMacDownlink_t));
LOGP(DRLCMAC, LOGL_DEBUG, "+++++++++++++++++++++++++ TX : Packet Paging Request +++++++++++++++++++++++++\n");
decode_gsm_rlcmac_downlink(pag_vec, mac_control_block);
LOGP(DRLCMAC, LOGL_DEBUG, "------------------------- TX : Packet Paging Request -------------------------\n");

This and other all other places really should use talloc to make finding
memory leaks more easy (e.g. by printing the leak report), the second part
is that we appear to leak this on every paging message sent by the PCU and
the third is actually a question. Should we use a GCC extension that
helps dealing with local variables? GCC can call a cleanup function
on exit of the scope, an example can be seen here[1] nad this[2] is
the description of the feature.


[1] https://mail.gnome.org/archives/gtk-devel-list/2011-November/msg00050.html
[2] http://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html#Variable-Attributes

- Holger Freyther <hfreyther at sysmocom.de>       http://www.sysmocom.de/
* sysmocom - systems for mobile communications GmbH
* Schivelbeiner Str. 5
* 10439 Berlin, Germany
* Sitz / Registered office: Berlin, HRB 134158 B
* Geschaeftsfuehrer / Managing Directors: Holger Freyther, Harald Welte

More information about the osmocom-net-gprs mailing list