btf_loader: Plug leak when bailing out due to unknown tag
Fixes this coverity report:
Error: RESOURCE_LEAK (CWE-772): [#def2]
dwarves-1.13/btf_loader.c:342: alloc_fn: Storage is returned from allocation function "zalloc".
dwarves-1.13/btf_loader.c:342: var_assign: Assigning: "tag" = storage returned from "zalloc(40UL)".
dwarves-1.13/btf_loader.c:354: leaked_storage: Variable "tag" going out of scope leaks the storage it points to.
# 352| default:
# 353| printf("%s: FOO %d\n\n", __func__, type);
# 354|-> return 0;
# 355| }
# 356|
Reported-by: William Cohen <wcohen@redhat.com>
Fixes: 472256d3c57b ("btf_loader: Introduce a loader for the BTF format")
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
diff --git a/btf_loader.c b/btf_loader.c
index f5e866d..f08ed5d 100644
--- a/btf_loader.c
+++ b/btf_loader.c
@@ -350,7 +350,8 @@
case BTF_KIND_RESTRICT: tag->tag = DW_TAG_restrict_type; break;
case BTF_KIND_VOLATILE: tag->tag = DW_TAG_volatile_type; break;
default:
- printf("%s: FOO %d\n\n", __func__, type);
+ free(tag);
+ printf("%s: Unknown type %d\n\n", __func__, type);
return 0;
}