diff mbox series

[1/3] libkmod: kmod_builtin_get_modinfo: free modinfo on error

Message ID 20201129164737.135866-1-yauheni.kaliuta@redhat.com (mailing list archive)
State New, archived
Headers show
Series [1/3] libkmod: kmod_builtin_get_modinfo: free modinfo on error | expand

Commit Message

Yauheni Kaliuta Nov. 29, 2020, 4:47 p.m. UTC
The function allocates array but on building it if get_string()
fails it returns the error leaving the array allocated. The caller
does not care about it in error case either.

Free it to fix memory leak.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
---
 libkmod/libkmod-builtin.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Lucas De Marchi Dec. 1, 2020, 10:06 a.m. UTC | #1
Thanks, those 3 fixes were applied.

Lucas De Marchi

On Sun, Nov 29, 2020 at 8:47 AM Yauheni Kaliuta
<yauheni.kaliuta@redhat.com> wrote:
>
> The function allocates array but on building it if get_string()
> fails it returns the error leaving the array allocated. The caller
> does not care about it in error case either.
>
> Free it to fix memory leak.
>
> Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
> ---
>  libkmod/libkmod-builtin.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/libkmod/libkmod-builtin.c b/libkmod/libkmod-builtin.c
> index aaec5ddb0609..fc9a37644261 100644
> --- a/libkmod/libkmod-builtin.c
> +++ b/libkmod/libkmod-builtin.c
> @@ -314,6 +314,7 @@ ssize_t kmod_builtin_get_modinfo(struct kmod_ctx *ctx, const char *modname,
>                 offset = get_string(iter, pos, &line, &linesz);
>                 if (offset <= 0) {
>                         count = (offset) ? -errno : -EOF;
> +                       free(*modinfo);
>                         goto fail;
>                 }
>
> --
> 2.29.2
>
diff mbox series

Patch

diff --git a/libkmod/libkmod-builtin.c b/libkmod/libkmod-builtin.c
index aaec5ddb0609..fc9a37644261 100644
--- a/libkmod/libkmod-builtin.c
+++ b/libkmod/libkmod-builtin.c
@@ -314,6 +314,7 @@  ssize_t kmod_builtin_get_modinfo(struct kmod_ctx *ctx, const char *modname,
 		offset = get_string(iter, pos, &line, &linesz);
 		if (offset <= 0) {
 			count = (offset) ? -errno : -EOF;
+			free(*modinfo);
 			goto fail;
 		}