* [PATCH] KEYS: fix memory leak
@ 2016-04-12 12:11 Sudip Mukherjee
2016-04-12 18:06 ` David Howells
0 siblings, 1 reply; 2+ messages in thread
From: Sudip Mukherjee @ 2016-04-12 12:11 UTC (permalink / raw)
To: David Howells; +Cc: linux-kernel, Sudip Mukherjee
If the file read fails then we returned NULL as error but we missed
freeing buf.
Signed-off-by: Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>
---
scripts/insert-sys-cert.c | 1 +
1 file changed, 1 insertion(+)
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);
--
1.9.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] KEYS: fix memory leak
2016-04-12 12:11 [PATCH] KEYS: fix memory leak Sudip Mukherjee
@ 2016-04-12 18:06 ` David Howells
0 siblings, 0 replies; 2+ messages in thread
From: David Howells @ 2016-04-12 18:06 UTC (permalink / raw)
To: Sudip Mukherjee; +Cc: dhowells, linux-kernel, mkayaalp
Sudip Mukherjee <sudipm.mukherjee@gmail.com> 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);
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-04-12 18:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-12 12:11 [PATCH] KEYS: fix memory leak Sudip Mukherjee
2016-04-12 18:06 ` David Howells
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.