talloc, malloc and memory leaks

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/osmocom-net-gprs@lists.osmocom.org/.

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


Hi,

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);
LOGPC(DCSN1, LOGL_NOTICE, "\n");
LOGP(DRLCMAC, LOGL_DEBUG, "------------------------- TX : Packet Paging Request -------------------------\n");
bitvec_free(pag_vec);

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.

holger

[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