commit b61f2f54a708661d4a659f6fb698f6bb627f3211
parent 1bee641ebecfca492d4b6e1d885259348dab5322
Author: Christian Grothoff <christian@grothoff.org>
Date: Wed, 29 Jul 2026 23:55:30 +0200
fix small memory leak in ELF extractor
Diffstat:
1 file changed, 21 insertions(+), 11 deletions(-)
diff --git a/src/plugins/elf_extractor.c b/src/plugins/elf_extractor.c
@@ -434,7 +434,7 @@ getProgramHdr (struct EXTRACTOR_ExtractContext *ec,
/**
- * @return the string (offset into data, do NOT free), NULL on error
+ * @return the string, NULL on error; the caller must free() it
*/
static char *
readStringTable (struct EXTRACTOR_ExtractContext *ec,
@@ -482,6 +482,22 @@ readStringTable (struct EXTRACTOR_ExtractContext *ec,
} \
} while (0)
+/**
+ * Like ADD(), but for a heap-allocated @a s that must be released on
+ * every path. ADD()'s early return -- taken whenever the application
+ * asks extraction to stop -- would otherwise jump over the free().
+ */
+#define ADD_FREE(s, type) do { \
+ int stop_ = (0 != ec->proc (ec->cls, "elf", type, \
+ EXTRACTOR_METAFORMAT_UTF8, "text/plain", \
+ s, strlen (s) + 1)); \
+ free (s); \
+ if (stop_) \
+ { \
+ return; \
+ } \
+} while (0)
+
/**
* Main entry method for the 'application/x-executable' extraction plugin.
@@ -759,11 +775,8 @@ EXTRACTOR_elf_extract_method (struct EXTRACTOR_ExtractContext *ec)
/* "source" of the dependencies: path
to dynamic libraries */
if (NULL != rpath)
- {
- ADD (rpath,
- EXTRACTOR_METATYPE_LIBRARY_SEARCH_PATH);
- free (rpath);
- }
+ ADD_FREE (rpath,
+ EXTRACTOR_METATYPE_LIBRARY_SEARCH_PATH);
break;
}
case DT_NEEDED:
@@ -776,11 +789,8 @@ EXTRACTOR_elf_extract_method (struct EXTRACTOR_ExtractContext *ec)
stringIdx,
dyn.d_un.d_val);
if (NULL != needed)
- {
- ADD (needed,
- EXTRACTOR_METATYPE_LIBRARY_DEPENDENCY);
- free (needed);
- }
+ ADD_FREE (needed,
+ EXTRACTOR_METATYPE_LIBRARY_DEPENDENCY);
break;
}
}