From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13257 invoked by alias); 27 Oct 2007 15:26:33 -0000 Received: (qmail 13241 invoked by uid 22791); 27 Oct 2007 15:26:32 -0000 X-Spam-Check-By: sourceware.org Received: from ns.suse.de (HELO mx1.suse.de) (195.135.220.2) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sat, 27 Oct 2007 15:26:30 +0000 Received: from Relay2.suse.de (mail2.suse.de [195.135.221.8]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.suse.de (Postfix) with ESMTP id 4129115844 for ; Sat, 27 Oct 2007 17:26:27 +0200 (CEST) From: Andreas Jaeger To: libc-hacker@sources.redhat.com Subject: Fix BZ#3112: Memory leak in backtrace OpenPGP: id=C272A126; url=http://www.suse.de/~aj/keys.txt Date: Sat, 27 Oct 2007 15:26:00 -0000 Message-ID: <878x5opoim.fsf@suse.de> User-Agent: Gnus/5.110007 (No Gnus v0.7) Emacs/22.1 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2007-10/txt/msg00024.txt.bz2 --=-=-= Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Content-length: 5041 The appended patch frees the dlopened object if we check for memory leaks. Tested on Linux/x86-64 (which uses the ia64 code). ok to commit? Andreas 2007-10-27 Andreas Jaeger [BZ #3112] * sysdeps/ia64/backtrace.c (init): Free shared library. (__cleanup): Free shared library when exiting. * sysdeps/i386/backtrace.c (init): Free shared library. (__cleanup): Free shared library when exiting. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Index: sysdeps/i386/backtrace.c --- sysdeps/i386/backtrace.c 14 Jun 2005 15:54:05 -0000 1.7 +++ sysdeps/i386/backtrace.c 27 Oct 2007 15:02:27 -0000 @@ -1,5 +1,5 @@ /* Return backtrace of current program state. - Copyright (C) 1998, 2000, 2003, 2004, 2005 Free Software Foundation, In= c. + Copyright (C) 1998, 2000, 2003, 2004, 2005, 2007 Free Software Foundati= on, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 1998. =20 @@ -36,21 +36,26 @@ static _Unwind_Reason_Code (*unwind_back static _Unwind_Ptr (*unwind_getip) (struct _Unwind_Context *); static _Unwind_Ptr (*unwind_getcfa) (struct _Unwind_Context *); static _Unwind_Ptr (*unwind_getgr) (struct _Unwind_Context *, int); +static void *libgcc_handle; =20 static void init (void) { - void *handle =3D __libc_dlopen ("libgcc_s.so.1"); + libgcc_handle =3D __libc_dlopen ("libgcc_s.so.1"); =20 - if (handle =3D=3D NULL) + if (libgcc_handle =3D=3D NULL) return; =20 - unwind_backtrace =3D __libc_dlsym (handle, "_Unwind_Backtrace"); - unwind_getip =3D __libc_dlsym (handle, "_Unwind_GetIP"); - unwind_getcfa =3D __libc_dlsym (handle, "_Unwind_GetCFA"); - unwind_getgr =3D __libc_dlsym (handle, "_Unwind_GetGR"); + unwind_backtrace =3D __libc_dlsym (libgcc_handle, "_Unwind_Backtrace"); + unwind_getip =3D __libc_dlsym (libgcc_handle, "_Unwind_GetIP"); + unwind_getcfa =3D __libc_dlsym (libgcc_handle, "_Unwind_GetCFA"); + unwind_getgr =3D __libc_dlsym (libgcc_handle, "_Unwind_GetGR"); if (unwind_getip =3D=3D NULL || unwind_getgr =3D=3D NULL || unwind_getcf= a =3D=3D NULL) - unwind_backtrace =3D NULL; + { + unwind_backtrace =3D NULL; + __libc_dlclose (libgcc_handle); + libgcc_handle =3D NULL; + } } #else # define unwind_backtrace _Unwind_Backtrace @@ -142,3 +147,16 @@ __backtrace (array, size) } weak_alias (__backtrace, backtrace) libc_hidden_def (__backtrace) + +#ifdef SHARED +static void +__cleanup (void) +{ + if (libgcc_handle) + __libc_dlclose (libgcc_handle); +} + +/* Make sure the shared object is freed if we want to free everything + before exiting. */ +text_set_element (__libc_subfreeres, __cleanup); +#endif =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Index: sysdeps/ia64/backtrace.c --- sysdeps/ia64/backtrace.c 14 Jun 2005 15:54:05 -0000 1.3 +++ sysdeps/ia64/backtrace.c 27 Oct 2007 15:02:27 -0000 @@ -1,5 +1,5 @@ /* Return backtrace of current program state. - Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2003, 2004, 2005, 2007 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Jakub Jelinek , 2003. =20 @@ -33,19 +33,24 @@ struct trace_arg #ifdef SHARED static _Unwind_Reason_Code (*unwind_backtrace) (_Unwind_Trace_Fn, void *); static _Unwind_Ptr (*unwind_getip) (struct _Unwind_Context *); +static void *libgcc_handle; =20 static void init (void) { - void *handle =3D __libc_dlopen ("libgcc_s.so.1"); + libgcc_handle =3D __libc_dlopen ("libgcc_s.so.1"); =20 - if (handle =3D=3D NULL) + if (libgcc_handle =3D=3D NULL) return; =20 - unwind_backtrace =3D __libc_dlsym (handle, "_Unwind_Backtrace"); - unwind_getip =3D __libc_dlsym (handle, "_Unwind_GetIP"); + unwind_backtrace =3D __libc_dlsym (libgcc_handle, "_Unwind_Backtrace"); + unwind_getip =3D __libc_dlsym (libgcc_handle, "_Unwind_GetIP"); if (unwind_getip =3D=3D NULL) - unwind_backtrace =3D NULL; + { + unwind_backtrace =3D NULL; + __libc_dlclose (libgcc_handle); + libgcc_handle =3D NULL; + } } #else # define unwind_backtrace _Unwind_Backtrace @@ -91,3 +96,16 @@ __backtrace (array, size) } weak_alias (__backtrace, backtrace) libc_hidden_def (__backtrace) + +#ifdef SHARED +static void +__cleanup (void) +{ + if (libgcc_handle) + __libc_dlclose (libgcc_handle); +} + +/* Make sure the shared object is freed if we want to free everything + before exiting. */ +text_set_element (__libc_subfreeres, __cleanup); +#endif --=20 Andreas Jaeger, Director Platform / openSUSE, aj@suse.de SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG N=FCrnberg) Maxfeldstr. 5, 90409 N=FCrnberg, Germany GPG fingerprint =3D 93A3 365E CE47 B889 DF7F FED1 389A 563C C272 A126 --=-=-= Content-Type: application/pgp-signature Content-length: 193 -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.4-svn0 (GNU/Linux) iD8DBQFHI1ihOJpWPMJyoSYRAmpjAJ0atjsf16QAbCktyeKJKorIM3TcwQCdEcEo 1CKL+3X6dgc6ZwpkgzNN14o= =AIS3 -----END PGP SIGNATURE----- --=-=-=--