libkmod: kmod_builtin_get_modinfo: free modinfo on error
authorYauheni Kaliuta <yauheni.kaliuta@redhat.com>
Sun, 29 Nov 2020 16:47:35 +0000 (18:47 +0200)
committerLucas De Marchi <lucas.demarchi@intel.com>
Tue, 1 Dec 2020 08:44:17 +0000 (00:44 -0800)
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

index aaec5dd..fc9a376 100644 (file)
@@ -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;
                }