[LEDE-DEV] [PATCH] ubox: Fix some memory leaks

Felix Fietkau nbd at nbd.name
Mon Dec 19 00:01:24 PST 2016


On 2016-12-18 02:12, Rosen Penev wrote:
> Avoids leaking memory when exiting early.
> 
> Signed-off by: Rosen <rosenp at gmail.com>
> ---
>  kmodloader.c        | 8 ++++++--
>  log/logd.c          | 2 +-
>  validate/validate.c | 4 +++-
>  3 files changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/kmodloader.c b/kmodloader.c
> index 40edbf0..f80835a 100644
> --- a/kmodloader.c
> +++ b/kmodloader.c
> @@ -775,11 +775,15 @@ static int main_loader(int argc, char **argv)
>  	strcpy(path, dir);
>  	strcat(path, "*");
>  
> -	if (scan_loaded_modules())
> +	if (scan_loaded_modules()) {
> +		free (path);
>  		return -1;
> +	}
>  
> -	if (scan_module_folders())
> +	if (scan_module_folders()) {
> +		free (path);
>  		return -1;
> +	}
>  
>  	syslog(LOG_INFO, "kmodloader: loading kernel modules from %s\n", path);
>  
> diff --git a/log/logd.c b/log/logd.c
> index d778909..915348e 100644
> --- a/log/logd.c
> +++ b/log/logd.c
> @@ -84,7 +84,7 @@ read_log(struct ubus_context *ctx, struct ubus_object *obj,
>  		struct blob_attr *msg)
>  {
>  	struct client *cl;
> -	struct blob_attr *tb[__READ_MAX];
> +	struct blob_attr *tb[__READ_MAX] = { 0 };
>  	struct log_head *l;
>  	int count = 0;
>  	int fds[2];
This change is not necessary, and it's not related to any memory leaks
at all. If you want to silence compiler warnings, remove the 'if (msg)'
null pointer checks, you can assume msg to be non-NULL, as most other
ubus services do.
However, please do that in a separate patch.

- Felix



More information about the Lede-dev mailing list