From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 119190 invoked by alias); 3 Oct 2019 16:34:05 -0000 Mailing-List: contact gdb-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: , Sender: gdb-cvs-owner@sourceware.org List-Subscribe: Sender: gdb-cvs-owner@sourceware.org Received: (qmail 119100 invoked by uid 10018); 3 Oct 2019 16:34:04 -0000 Date: Thu, 03 Oct 2019 16:34:00 -0000 Message-ID: <20191003163404.119098.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jose E.Marchesi To: bfd-cvs@sourceware.org, gdb-cvs@sourceware.org Subject: [binutils-gdb] libctf: fix refcount leak in ctf_import X-Act-Checkin: binutils-gdb X-Git-Author: Nick Alcock X-Git-Refname: refs/heads/master X-Git-Oldrev: 9323dd869dfe481d46512c7f9b1a30d0b7d2d7c4 X-Git-Newrev: ad613f1d0693e02bdc86047c479315d5f969e2f7 X-SW-Source: 2019-10/txt/msg00063.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ad613f1d0693e02bdc86047c479315d5f969e2f7 commit ad613f1d0693e02bdc86047c479315d5f969e2f7 Author: Nick Alcock Date: Tue Sep 17 06:59:31 2019 +0100 libctf: fix refcount leak in ctf_import Calling ctf_import (fp, NULL) to cancel out a pre-existing import leaked the refcnt increment on the parent, so it could never be freed. New in v4. libctf/ * ctf-open.c (ctf_import): Do not leak a ctf_file_t ref on every ctf_import after the first for a given file. Diff: --- libctf/ChangeLog | 5 +++++ libctf/ctf-open.c | 2 ++ 2 files changed, 7 insertions(+) diff --git a/libctf/ChangeLog b/libctf/ChangeLog index b7f12d8..982c335 100644 --- a/libctf/ChangeLog +++ b/libctf/ChangeLog @@ -1,5 +1,10 @@ 2019-09-23 Nick Alcock + * ctf-open.c (ctf_import): Do not leak a ctf_file_t ref on every + ctf_import after the first for a given file. + +2019-09-23 Nick Alcock + * ctf-impl.h (ctf_str_append_noerr): Declare. * ctf-util.c (ctf_str_append_noerr): Define in terms of ctf_str_append. diff --git a/libctf/ctf-open.c b/libctf/ctf-open.c index 4a95b7f..aedf390 100644 --- a/libctf/ctf-open.c +++ b/libctf/ctf-open.c @@ -1778,6 +1778,7 @@ ctf_import (ctf_file_t *fp, ctf_file_t *pfp) if (fp->ctf_parent != NULL) { + fp->ctf_parent->ctf_refcnt--; ctf_file_close (fp->ctf_parent); fp->ctf_parent = NULL; } @@ -1793,6 +1794,7 @@ ctf_import (ctf_file_t *fp, ctf_file_t *pfp) fp->ctf_flags |= LCTF_CHILD; pfp->ctf_refcnt++; } + fp->ctf_parent = pfp; return 0; }