Re: [PATCH] KEYS: fix memory leak

From: David Howells
Date: Tue Apr 12 2016 - 14:06:20 EST


Sudip Mukherjee <sudipm.mukherjee@xxxxxxxxx> wrote:

> If the file read fails then we returned NULL as error but we missed
> freeing buf.

It's not a particularly critical error since it's a build-time script rather
than the kernel. Possibly read_file() and map_file() should just exit upon
encountering an error rather than returning.

David

> diff --git a/scripts/insert-sys-cert.c b/scripts/insert-sys-cert.c
> index 8902836..b98a0b1 100644
> --- a/scripts/insert-sys-cert.c
> +++ b/scripts/insert-sys-cert.c
> @@ -251,6 +251,7 @@ static char *read_file(char *file_name, int *size)
> if (read(fd, buf, *size) != *size) {
> perror("File read failed");
> close(fd);
> + free(buf);
> return NULL;
> }
> close(fd);