diff options
author | Andy Fiddaman <omnios@citrus-it.co.uk> | 2020-11-10 23:31:51 +0000 |
---|---|---|
committer | Andy Fiddaman <omnios@citrus-it.co.uk> | 2020-11-12 21:15:20 +0000 |
commit | a676209deb2ce5d0c98f331659de25e2483f8c4c (patch) | |
tree | ee2f5ed90711752a745594283ac1da73feb4bd84 | |
parent | effb27ee30c48fe502152c38487ced379d9f8693 (diff) | |
download | illumos-joyent-a676209deb2ce5d0c98f331659de25e2483f8c4c.tar.gz |
13252 ctf_update()/ctf_dwarf_convert_function() leak memory
Reviewed by: Robert Mustacchi <rm@fingolfin.org>
Approved by: Dan McDonald <danmcd@joyent.com>
-rw-r--r-- | usr/src/common/ctf/ctf_create.c | 2 | ||||
-rw-r--r-- | usr/src/common/ctf/ctf_impl.h | 6 | ||||
-rw-r--r-- | usr/src/common/ctf/ctf_open.c | 5 | ||||
-rw-r--r-- | usr/src/lib/libctf/common/ctf_dwarf.c | 5 |
4 files changed, 17 insertions, 1 deletions
diff --git a/usr/src/common/ctf/ctf_create.c b/usr/src/common/ctf/ctf_create.c index c1027aa60e..abbfeddc76 100644 --- a/usr/src/common/ctf/ctf_create.c +++ b/usr/src/common/ctf/ctf_create.c @@ -26,6 +26,7 @@ */ /* * Copyright 2020 Joyent, Inc. + * Copyright 2020 OmniOS Community Edition (OmniOSce) Association. */ #include <sys/sysmacros.h> @@ -671,6 +672,7 @@ ctf_update(ctf_file_t *fp) nfp->ctf_refcnt = fp->ctf_refcnt; nfp->ctf_flags |= fp->ctf_flags & ~LCTF_DIRTY; + nfp->ctf_flags |= LCTF_FREE; nfp->ctf_dthash = fp->ctf_dthash; nfp->ctf_dthashlen = fp->ctf_dthashlen; nfp->ctf_dtdefs = fp->ctf_dtdefs; diff --git a/usr/src/common/ctf/ctf_impl.h b/usr/src/common/ctf/ctf_impl.h index 7064abad15..d4ab96c4de 100644 --- a/usr/src/common/ctf/ctf_impl.h +++ b/usr/src/common/ctf/ctf_impl.h @@ -26,6 +26,7 @@ */ /* * Copyright 2020 Joyent, Inc. + * Copyright 2020 OmniOS Community Edition (OmniOSce) Association. */ #ifndef _CTF_IMPL_H @@ -248,6 +249,11 @@ struct ctf_file { #define LCTF_CHILD 0x0002 /* CTF container is a child */ #define LCTF_RDWR 0x0004 /* CTF container is writable */ #define LCTF_DIRTY 0x0008 /* CTF container has been modified */ +/* + * The storage for this CTF container was allocated via ctf_data_alloc() + * and libctf should free it with ctf_data_free() on close. + */ +#define LCTF_FREE 0x0010 #define CTF_ELF_SCN_NAME ".SUNW_ctf" diff --git a/usr/src/common/ctf/ctf_open.c b/usr/src/common/ctf/ctf_open.c index 82b396e825..fe0644b1b0 100644 --- a/usr/src/common/ctf/ctf_open.c +++ b/usr/src/common/ctf/ctf_open.c @@ -26,6 +26,7 @@ */ /* * Copyright (c) 2015, Joyent, Inc. All rights reserved. + * Copyright 2020 OmniOS Community Edition (OmniOSce) Association. */ #include <ctf_impl.h> @@ -936,6 +937,10 @@ ctf_close(ctf_file_t *fp) if (fp->ctf_strtab.cts_data != NULL) ctf_sect_munmap(&fp->ctf_strtab); } + if (fp->ctf_flags & LCTF_FREE) { + ctf_data_free((void *)fp->ctf_data.cts_data, + fp->ctf_data.cts_size); + } if (fp->ctf_data.cts_name != _CTF_NULLSTR && fp->ctf_data.cts_name != NULL) { diff --git a/usr/src/lib/libctf/common/ctf_dwarf.c b/usr/src/lib/libctf/common/ctf_dwarf.c index e2cd9414dc..8163b145e4 100644 --- a/usr/src/lib/libctf/common/ctf_dwarf.c +++ b/usr/src/lib/libctf/common/ctf_dwarf.c @@ -2290,8 +2290,10 @@ ctf_dwarf_convert_function(ctf_cu_t *cup, Dwarf_Die die) name, ctf_die_offset(cup, die)); if ((ret = ctf_dwarf_boolean(cup, die, DW_AT_declaration, &b)) != 0) { - if (ret != ENOENT) + if (ret != ENOENT) { + ctf_free(name, strlen(name) + 1); return (ret); + } } else if (b != 0) { /* * GCC7 at least creates empty DW_AT_declarations for functions @@ -2302,6 +2304,7 @@ ctf_dwarf_convert_function(ctf_cu_t *cup, Dwarf_Die die) */ ctf_dprintf("ignoring declaration of function %s (die %llx)\n", name, ctf_die_offset(cup, die)); + ctf_free(name, strlen(name) + 1); return (0); } |