This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] memory leak in _reclaim_reent


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

While looking at the reentrancy code I've found three variables that
are surely malloc'd, but are not freed in _reclaim_reent(). Of these,
two variables, _misc and _signal_buf, cause a leak only if
_REENT_SMALL is defined. The third one, _sig_func seems to always
cause a leak.

The patch for this is simple and is attached, but I have a doubt about
it regarding _sig_func (the table of function pointers to signal
handlers): what if a signal is raised during _reclaim_reent()? Without
this patch, _sig_func is not freed so memory is leaked but the table
remains valid. With this patch no memory is leaked but a signal after
the free may be a problem. I do not have an answer to this question.
If needed, I can provide an alternate patch to only free the first two
variables.

newlib/ChangeLog
2013-06-23  Terraneo Federico  <fede.tft@hotmail.it>

	* libc/reent/reent.c (_reclaim_reent): Free also _misc,
	  _signal_buf and _sig_func.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJRx2MlAAoJECkLFtN5Xr9fPMAH/3w3aFPBqrx5Pn8X6wM2sPn/
Ziwa4CYHe+UdRCQSxplLxnV6NHVt0D3cVK1wCdDI7bif82uaJsA62mi+naGZN3Ys
8xoMfFw1MHYZ3cYy/gOne4m9i+2mjtHt/PMgGgSL1/F6xLlGAgVuajHdYWDgkuY6
KT0S8xlIch+vtlXPPpnQOnDhR5/mjXQ0/8o+VMMTRS3EHv5cr1tnS7+UT5DNuyF+
qumZeNOidl9//mwggLdek83+p9HEZ02wM2I22GnFaY2p9iRXs04l+g8w2vz0xC9g
dKw+Vd0G3fgLK3/HaGuVLomI6KxUHpmIeyHEX1VhNDEtbsJzBTyuaqy5b/1istE=
=LgeH
-----END PGP SIGNATURE-----
diff -ruN a/newlib/libc/reent/reent.c b/newlib/libc/reent/reent.c
--- a/newlib/libc/reent/reent.c	2013-05-16 14:29:28.000000000 +0200
+++ b/newlib/libc/reent/reent.c	2013-06-23 22:39:13.075480394 +0200
@@ -87,6 +87,10 @@
 	_free_r (ptr, ptr->_localtime_buf);
       if (ptr->_asctime_buf)
 	_free_r (ptr, ptr->_asctime_buf);
+	  if (ptr->_signal_buf)
+	_free_r (ptr, ptr->_signal_buf);
+	  if (ptr->_misc)
+	_free_r (ptr, ptr->_misc);
 #endif
 
 #ifndef _REENT_GLOBAL_ATEXIT
@@ -110,6 +114,8 @@
 
       if (ptr->_cvtbuf)
 	_free_r (ptr, ptr->_cvtbuf);
+      if (ptr->_sig_func)
+	_free_r (ptr, ptr->_sig_func);
 
       if (ptr->__sdidinit)
 	{

Attachment: reclaim_reent.patch.sig
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]