* [PATCH] DTC: Fix memory leak on flatname. @ 2016-07-10 22:16 Jean-Christophe Dubois [not found] ` <1468189012-1584-1-git-send-email-jcd-WBS85hRCVJbxB9160cZjhg@public.gmane.org> 0 siblings, 1 reply; 2+ messages in thread From: Jean-Christophe Dubois @ 2016-07-10 22:16 UTC (permalink / raw) To: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA, david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+, jdl-CYoMK+44s/E Cc: Jean-Christophe Dubois If flatname was not referenced by the "node" structure, the reference to the allocated string is lost at function exit. We need to free it if is not used by "node". Signed-off-by: Jean-Christophe Dubois <jcd-WBS85hRCVJbxB9160cZjhg@public.gmane.org> --- flattree.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/flattree.c b/flattree.c index ec14954..089b976 100644 --- a/flattree.c +++ b/flattree.c @@ -797,6 +797,10 @@ static struct node *unflatten_tree(struct inbuf *dtbuf, } } while (val != FDT_END_NODE); + if (node->name != flatname) { + free(flatname); + } + return node; } -- 2.7.4 ^ permalink raw reply related [flat|nested] 2+ messages in thread
[parent not found: <1468189012-1584-1-git-send-email-jcd-WBS85hRCVJbxB9160cZjhg@public.gmane.org>]
* Re: [PATCH] DTC: Fix memory leak on flatname. [not found] ` <1468189012-1584-1-git-send-email-jcd-WBS85hRCVJbxB9160cZjhg@public.gmane.org> @ 2016-07-11 1:29 ` David Gibson 0 siblings, 0 replies; 2+ messages in thread From: David Gibson @ 2016-07-11 1:29 UTC (permalink / raw) To: Jean-Christophe Dubois Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA, jdl-CYoMK+44s/E [-- Attachment #1: Type: text/plain, Size: 1106 bytes --] On Mon, Jul 11, 2016 at 12:16:52AM +0200, Jean-Christophe Dubois wrote: > If flatname was not referenced by the "node" structure, the reference to the > allocated string is lost at function exit. > > We need to free it if is not used by "node". > > Signed-off-by: Jean-Christophe Dubois <jcd-WBS85hRCVJbxB9160cZjhg@public.gmane.org> TBH, I'm not generally particularly fussed by memory leaks in dtc, since it only has a short runtime. Still, I've applied this fix because, why not. > --- > flattree.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/flattree.c b/flattree.c > index ec14954..089b976 100644 > --- a/flattree.c > +++ b/flattree.c > @@ -797,6 +797,10 @@ static struct node *unflatten_tree(struct inbuf *dtbuf, > } > } while (val != FDT_END_NODE); > > + if (node->name != flatname) { > + free(flatname); > + } > + > return node; > } > -- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 819 bytes --] ^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-07-11 1:29 UTC | newest] Thread overview: 2+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-07-10 22:16 [PATCH] DTC: Fix memory leak on flatname Jean-Christophe Dubois [not found] ` <1468189012-1584-1-git-send-email-jcd-WBS85hRCVJbxB9160cZjhg@public.gmane.org> 2016-07-11 1:29 ` David Gibson
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).