From ad613f1d0693e02bdc86047c479315d5f969e2f7 Mon Sep 17 00:00:00 2001 From: Nick Alcock Date: Tue, 17 Sep 2019 06:59:31 +0100 Subject: [PATCH] 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. --- libctf/ChangeLog | 5 +++++ libctf/ctf-open.c | 2 ++ 2 files changed, 7 insertions(+) diff --git a/libctf/ChangeLog b/libctf/ChangeLog index b7f12d8e092..982c3355699 100644 --- a/libctf/ChangeLog +++ b/libctf/ChangeLog @@ -1,3 +1,8 @@ +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. diff --git a/libctf/ctf-open.c b/libctf/ctf-open.c index 4a95b7f38a5..aedf39086a2 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; } -- 2.30.2