Gentoo Archives: gentoo-commits

From: Mike Frysinger <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage-utils:master commit in: libq/, /
Date: Thu, 29 Dec 2016 02:25:56
Message-Id: 1482965648.8f6a879b16fc664b03c361ae203def52220d0cb9.vapier@gentoo
1 commit: 8f6a879b16fc664b03c361ae203def52220d0cb9
2 Author: Mike Frysinger <vapier <AT> gentoo <DOT> org>
3 AuthorDate: Wed Dec 28 22:54:08 2016 +0000
4 Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org>
5 CommitDate: Wed Dec 28 22:54:08 2016 +0000
6 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=8f6a879b
7
8 add cleanup logic to handle specific leaks
9
10 There's a few code paths that we leak resources because we know
11 we're exiting (soon). Add some logic to avoid false positives.
12
13 libq/libq.h | 4 ++++
14 main.c | 6 ++++--
15 main.h | 13 +++++++++++++
16 q.c | 8 ++++----
17 4 files changed, 25 insertions(+), 6 deletions(-)
18
19 diff --git a/libq/libq.h b/libq/libq.h
20 index 6a74a48..94254e1 100644
21 --- a/libq/libq.h
22 +++ b/libq/libq.h
23 @@ -12,6 +12,10 @@ FILE *warnout;
24 #define warnfp(fmt, args...) warnf(fmt ": %s" , ## args , strerror(errno))
25 #define _err(wfunc, fmt, args...) \
26 do { \
27 + if (USE_CLEANUP) { \
28 + if (warnout != stderr) \
29 + fclose(warnout); \
30 + } \
31 warnout = stderr; \
32 wfunc(fmt , ## args); \
33 exit(EXIT_FAILURE); \
34
35 diff --git a/main.c b/main.c
36 index 543ac36..9921363 100644
37 --- a/main.c
38 +++ b/main.c
39 @@ -1102,13 +1102,15 @@ void reinitialize_as_needed(void)
40 if (reinitialize)
41 array_for_each(overlays, n, overlay) {
42 ret = initialize_flat(overlay, CACHE_EBUILD, true);
43 - IF_DEBUG(free((void *)ret));
44 + if (USE_CLEANUP)
45 + free((void *)ret);
46 }
47
48 if (reinitialize_metacache)
49 array_for_each(overlays, n, overlay) {
50 ret = initialize_flat(overlay, CACHE_METADATA, true);
51 - IF_DEBUG(free((void *)ret));
52 + if (USE_CLEANUP)
53 + free((void *)ret);
54 }
55 }
56
57
58 diff --git a/main.h b/main.h
59 index 6848a9f..d3df8b1 100644
60 --- a/main.h
61 +++ b/main.h
62 @@ -95,6 +95,19 @@
63 # define IF_DEBUG(x)
64 #endif
65
66 +#undef USE_CLEANUP
67 +/* LSAN (Leak Sanitizer) will complain about things we leak. */
68 +#ifdef __SANITIZE_ADDRESS__
69 +# define USE_CLEANUP 1
70 +#endif
71 +/* Coverity catches some things we leak on purpose. */
72 +#ifdef __COVERITY__
73 +# define USE_CLEANUP 1
74 +#endif
75 +#ifndef USE_CLEANUP
76 +# define USE_CLEANUP 0
77 +#endif
78 +
79 #define GETOPT_LONG(A, a, ex) \
80 getopt_long(argc, argv, ex A ## _FLAGS, a ## _long_opts, NULL)
81
82
83 diff --git a/q.c b/q.c
84 index 6ee9aef..ea1fb4d 100644
85 --- a/q.c
86 +++ b/q.c
87 @@ -87,8 +87,8 @@ int q_main(int argc, char **argv)
88 case 'm':
89 if (optarg) {
90 const char *path = initialize_flat(optarg, CACHE_METADATA, true);
91 - if (path) { /* silence warning */ }
92 - IF_DEBUG(free((void *)path));
93 + if (USE_CLEANUP)
94 + free((void *)path);
95 reinitialize_metacache = -1;
96 } else
97 reinitialize_metacache = 1;
98 @@ -96,8 +96,8 @@ int q_main(int argc, char **argv)
99 case 'r':
100 if (optarg) {
101 const char *path = initialize_flat(optarg, CACHE_EBUILD, true);
102 - if (path) { /* silence warning */ }
103 - IF_DEBUG(free((void *)path));
104 + if (USE_CLEANUP)
105 + free((void *)path);
106 reinitialize = -1;
107 } else
108 reinitialize = 1;