diff options
author | 2015-08-18 11:09:28 -0400 | |
---|---|---|
committer | 2015-08-18 11:11:42 -0400 | |
commit | 51d892de53b850467de615774c2d26de007db649 (patch) | |
tree | ff9166a3649599f1c4e2052c5b2622c1e23b5142 /scanelf.c | |
parent | build: use pkg-config for libcap settings (diff) | |
download | pax-utils-51d892de53b850467de615774c2d26de007db649.tar.gz pax-utils-51d892de53b850467de615774c2d26de007db649.tar.bz2 pax-utils-51d892de53b850467de615774c2d26de007db649.zip |
debug: improve cleanup logic
Always set up the cleanup symbol and use it at C time rather than CPP.
We can delete the warning code since we clean those strings up now.
Add ASAN support so LSAN doesn't complain either.
Fix a bug in the leak checking when the -F flag is used -- normally we
don't allocate that string but set it to one of the argv constants.
Diffstat (limited to 'scanelf.c')
-rw-r--r-- | scanelf.c | 53 |
1 files changed, 26 insertions, 27 deletions
@@ -2264,7 +2264,10 @@ static int parseargs(int argc, char *argv[]) break; case 'F': { if (out_format) warn("You prob don't want to specify -F twice"); - out_format = optarg; + if (PAX_UTILS_CLEANUP) + out_format = xstrdup(optarg); + else + out_format = optarg; break; } case 'z': { @@ -2478,26 +2481,26 @@ static int parseargs(int argc, char *argv[]) ret = scanelf_dir(search_path); } -#ifdef __PAX_UTILS_CLEANUP - /* clean up */ - xarrayfree(ldpaths); - xarrayfree(find_sym_arr); - xarrayfree(find_lib_arr); - xarrayfree(find_section_arr); - free(find_sym); - free(find_lib); - free(find_section); - { - size_t n; - regex_t *preg; - array_for_each(find_sym_regex_arr, n, preg) - regfree(preg); - xarrayfree(find_sym_regex_arr); - } + if (PAX_UTILS_CLEANUP) { + /* clean up */ + xarrayfree(ldpaths); + xarrayfree(find_sym_arr); + xarrayfree(find_lib_arr); + xarrayfree(find_section_arr); + free(find_sym); + free(find_lib); + free(find_section); + { + size_t n; + regex_t *preg; + array_for_each(find_sym_regex_arr, n, preg) + regfree(preg); + xarrayfree(find_sym_regex_arr); + } - if (ldcache != 0) - munmap(ldcache, ldcache_size); -#endif + if (ldcache != 0) + munmap(ldcache, ldcache_size); + } return ret; } @@ -2544,15 +2547,16 @@ static void parseenv(void) qa_wx_load = get_split_env("QA_WX_LOAD"); } -#ifdef __PAX_UTILS_CLEANUP static void cleanup(void) { + if (!PAX_UTILS_CLEANUP) + return; + free(out_format); free(qa_textrels); free(qa_execstack); free(qa_wx_load); } -#endif int main(int argc, char *argv[]) { @@ -2562,12 +2566,7 @@ int main(int argc, char *argv[]) parseenv(); ret = parseargs(argc, argv); fclose(stdout); -#ifdef __PAX_UTILS_CLEANUP cleanup(); - warn("The calls to add/delete heap should be off:\n" - "\t- 1 due to the out_buffer not being freed in scanelf_fileat()\n" - "\t- 1 per QA_TEXTRELS/QA_EXECSTACK/QA_WX_LOAD"); -#endif return ret; } |