diff mbox series

[2/3] depmod: output_builtin_alias_bin: free idx on error path

Message ID 20201129164737.135866-2-yauheni.kaliuta@redhat.com (mailing list archive)
State New
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
idx is allocated in the beginning but it's not freed if there is
a failure after the allocation.

Change the error path: return immediately if idx allocation fails
and then free it in both success and error path at the end.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
---
 tools/depmod.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/tools/depmod.c b/tools/depmod.c
index 875e31480818..2c03dfe7dc28 100644
--- a/tools/depmod.c
+++ b/tools/depmod.c
@@ -2412,10 +2412,8 @@  static int output_builtin_alias_bin(struct depmod *depmod, FILE *out)
 		return 0;
 
 	idx = index_create();
-	if (idx == NULL) {
-		ret = -ENOMEM;
-		goto fail;
-	}
+	if (idx == NULL)
+		return -ENOMEM;
 
 	ret = kmod_module_get_builtin(depmod->ctx, &builtin);
 	if (ret < 0) {
@@ -2458,13 +2456,12 @@  static int output_builtin_alias_bin(struct depmod *depmod, FILE *out)
 
 	if (count)
 		index_write(idx, out);
-
-	index_destroy(idx);
-
 fail:
 	if (builtin)
 		kmod_module_unref_list(builtin);
 
+	index_destroy(idx);
+
 	return ret;
 }