Re: [PATCH] DTC: Fix memory leak on flatname.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



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@xxxxxxxxxxxxxxx>

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: signature.asc
Description: PGP signature


[Index of Archives]     [Device Tree]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux