aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2016-12-28 17:54:08 -0500
committerMike Frysinger <vapier@gentoo.org>2016-12-28 17:54:08 -0500
commit8f6a879b16fc664b03c361ae203def52220d0cb9 (patch)
treecb541a9806018a2fa85c2a1b04727a1e98982aa0
parentstart some likely/unlikely helpers (diff)
downloadportage-utils-8f6a879b16fc664b03c361ae203def52220d0cb9.tar.gz
portage-utils-8f6a879b16fc664b03c361ae203def52220d0cb9.tar.bz2
portage-utils-8f6a879b16fc664b03c361ae203def52220d0cb9.zip
add cleanup logic to handle specific leaks
There's a few code paths that we leak resources because we know we're exiting (soon). Add some logic to avoid false positives.
-rw-r--r--libq/libq.h4
-rw-r--r--main.c6
-rw-r--r--main.h13
-rw-r--r--q.c8
4 files changed, 25 insertions, 6 deletions
diff --git a/libq/libq.h b/libq/libq.h
index 6a74a48..94254e1 100644
--- a/libq/libq.h
+++ b/libq/libq.h
@@ -12,6 +12,10 @@ FILE *warnout;
#define warnfp(fmt, args...) warnf(fmt ": %s" , ## args , strerror(errno))
#define _err(wfunc, fmt, args...) \
do { \
+ if (USE_CLEANUP) { \
+ if (warnout != stderr) \
+ fclose(warnout); \
+ } \
warnout = stderr; \
wfunc(fmt , ## args); \
exit(EXIT_FAILURE); \
diff --git a/main.c b/main.c
index 543ac36..9921363 100644
--- a/main.c
+++ b/main.c
@@ -1102,13 +1102,15 @@ void reinitialize_as_needed(void)
if (reinitialize)
array_for_each(overlays, n, overlay) {
ret = initialize_flat(overlay, CACHE_EBUILD, true);
- IF_DEBUG(free((void *)ret));
+ if (USE_CLEANUP)
+ free((void *)ret);
}
if (reinitialize_metacache)
array_for_each(overlays, n, overlay) {
ret = initialize_flat(overlay, CACHE_METADATA, true);
- IF_DEBUG(free((void *)ret));
+ if (USE_CLEANUP)
+ free((void *)ret);
}
}
diff --git a/main.h b/main.h
index 6848a9f..d3df8b1 100644
--- a/main.h
+++ b/main.h
@@ -95,6 +95,19 @@
# define IF_DEBUG(x)
#endif
+#undef USE_CLEANUP
+/* LSAN (Leak Sanitizer) will complain about things we leak. */
+#ifdef __SANITIZE_ADDRESS__
+# define USE_CLEANUP 1
+#endif
+/* Coverity catches some things we leak on purpose. */
+#ifdef __COVERITY__
+# define USE_CLEANUP 1
+#endif
+#ifndef USE_CLEANUP
+# define USE_CLEANUP 0
+#endif
+
#define GETOPT_LONG(A, a, ex) \
getopt_long(argc, argv, ex A ## _FLAGS, a ## _long_opts, NULL)
diff --git a/q.c b/q.c
index 6ee9aef..ea1fb4d 100644
--- a/q.c
+++ b/q.c
@@ -87,8 +87,8 @@ int q_main(int argc, char **argv)
case 'm':
if (optarg) {
const char *path = initialize_flat(optarg, CACHE_METADATA, true);
- if (path) { /* silence warning */ }
- IF_DEBUG(free((void *)path));
+ if (USE_CLEANUP)
+ free((void *)path);
reinitialize_metacache = -1;
} else
reinitialize_metacache = 1;
@@ -96,8 +96,8 @@ int q_main(int argc, char **argv)
case 'r':
if (optarg) {
const char *path = initialize_flat(optarg, CACHE_EBUILD, true);
- if (path) { /* silence warning */ }
- IF_DEBUG(free((void *)path));
+ if (USE_CLEANUP)
+ free((void *)path);
reinitialize = -1;
} else
reinitialize = 1;