NSPR allocations not freed upon exit
Hal Duston <[email protected]> Tue, 19 Jul 2016 15:29:42 -0500
| Newsgroups | gmane.comp.mozilla.devel.nspr |
|---|---|
| Message-ID | <[email protected]> |
--bCsyhTFzCvuiizWE Content-Type: text/plain; charset=us-ascii Content-Disposition: inline I have three proposed patches to remove each of three initialization allocations that are not freed upon exit. The first patch frees pr_exe_loadmap in linking/prlink.c. In bug #96122, Wan-Teh Chang expressed concerns about it being referenced elsewhere. The patch resolves this by setting it to NULL after freeing it. This works as the reference checks for NULL before dereferencing pr_exe_load_map. The second patch frees the Table_List entries in misc/prerrortable.c. The third patch frees _pr_tpd_destructors in threads/prtpd.c. These patches are for 4.11, but they should easily apply against 4.12. Thanks, -- Hal Duston [email protected] --bCsyhTFzCvuiizWE Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="nspr-loadmap-memleak.patch" --- nspr/pr/src/linking/prlink.c.orig 2015-10-16 08:22:19.000000000 -0500 +++ nspr/pr/src/linking/prlink.c 2015-11-25 13:55:28.299996909 -0600 @@ -216,8 +216,9 @@ void _PR_InitLinker(void) */ void _PR_ShutdownLinker(void) { - /* FIXME: pr_exe_loadmap should be destroyed. */ - + PR_UnloadLibrary(pr_exe_loadmap); + pr_exe_loadmap = NULL; + PR_DestroyMonitor(pr_linker_lock); pr_linker_lock = NULL; --bCsyhTFzCvuiizWE Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="nspr-errortable-memleak.patch" --- nspr/pr/src/misc/compile-et.pl.orig 2015-10-16 08:22:19.000000000 -0500 +++ nspr/pr/src/misc/compile-et.pl 2015-11-25 15:54:55.031436108 -0600 @@ -94,6 +94,7 @@ while ($_ = <INPUT>) { print H "\n"; print H "extern void ", $table_name, "_InitializePRErrorTable","(void);\n"; +print H "extern void ", $table_name, "_CleanupPRErrorTable","(void);\n"; printf H "#define ERROR_TABLE_BASE_%s (%dL)\n", $table_name, $table_base; print C "\t{0, 0}\n"; @@ -104,5 +105,9 @@ print C "\n"; print C "void ", $table_name, "_InitializePRErrorTable", "(void) {\n"; print C " PR_ErrorInstallTable(&et);\n"; print C "}\n"; +print C "\n"; +print C "void ", $table_name, "_CleanupPRErrorTable", "(void) {\n"; +print C " PR_ErrorRemoveTable(&et);\n"; +print C "}\n"; 0; --- nspr/pr/include/prerror.h.orig 2015-10-16 08:22:19.000000000 -0500 +++ nspr/pr/include/prerror.h 2015-11-25 14:38:39.899983870 -0600 @@ -262,8 +262,7 @@ NSPR_API(const char * const *) PR_ErrorL ** FUNCTION: PR_ErrorInstallTable ** DESCRIPTION: ** Registers an error table with NSPR. Must be done exactly once per -** table. Memory pointed to by `table' must remain valid for the life -** of the process. +** table. Memory pointed to by `table' must remain valid until removed. ** ** NOT THREAD SAFE! ** @@ -272,6 +271,18 @@ NSPR_API(PRErrorCode) PR_ErrorInstallTab /*********************************************************************** +** FUNCTION: PR_ErrorRemoveTable +** DESCRIPTION: +** Removes an error table from NSPR. Must be done exactly once per +** table. Memory pointed to by `table' can be freed after removal. +** +** NOT THREAD SAFE! +** +***********************************************************************/ +NSPR_API(PRErrorCode) PR_ErrorRemoveTable(const struct PRErrorTable *table); + + +/*********************************************************************** ** FUNCTION: PR_ErrorInstallCallback ** DESCRIPTION: ** Registers an error localization plugin with NSPR. May be called --- nspr/pr/src/misc/prerrortable.c.orig 2015-10-16 08:22:19.000000000 -0500 +++ nspr/pr/src/misc/prerrortable.c 2015-11-25 14:38:26.599959279 -0600 @@ -181,6 +181,27 @@ PR_ErrorInstallTable(const struct PRErro return 0; } +PR_IMPLEMENT(PRErrorCode) +PR_ErrorRemoveTable(const struct PRErrorTable *table) +{ + struct PRErrorTableList *et; + struct PRErrorTableList *prev_et = NULL; + + for (et = Table_List; et; et = et->next) { + if (et->table == table) { + if (prev_et != NULL) + prev_et->next = et->next; + else + Table_List = NULL; + PR_Free(et); + break; + } + prev_et = et; + } + + return 0; +} + PR_IMPLEMENT(void) PR_ErrorInstallCallback(const char * const * languages, PRErrorCallbackLookupFn *lookup, --- nspr/pr/src/misc/prinit.c.orig 2015-10-16 08:22:19.000000000 -0500 +++ nspr/pr/src/misc/prinit.c 2015-11-25 14:38:30.383966276 -0600 @@ -379,6 +379,8 @@ PR_IMPLEMENT(PRStatus) PR_Cleanup() _PR_MD_EARLY_CLEANUP(); + nspr_CleanupPRErrorTable(); + _PR_CleanupMW(); _PR_CleanupTime(); _PR_CleanupDtoa(); --- nspr/pr/src/pthreads/ptthread.c.orig 2015-10-16 08:22:19.000000000 -0500 +++ nspr/pr/src/pthreads/ptthread.c 2015-11-25 15:09:32.180959047 -0600 @@ -1112,6 +1112,8 @@ PR_IMPLEMENT(PRStatus) PR_Cleanup(void) _PR_MD_EARLY_CLEANUP(); + nspr_CleanupPRErrorTable(); + _PR_CleanupMW(); _PR_CleanupTime(); _PR_CleanupDtoa(); --- nspr/pr/include/prerr.h.orig 2015-10-16 08:22:19.000000000 -0500 +++ nspr/pr/include/prerr.h 2015-11-25 16:32:57.198272103 -0600 @@ -244,6 +244,7 @@ #define PR_MAX_ERROR (-5924L) extern void nspr_InitializePRErrorTable(void); +extern void nspr_CleanupPRErrorTable(void); #define ERROR_TABLE_BASE_nspr (-6000L) #endif /* prerr_h___ */ --- nspr/pr/src/misc/prerr.c.orig 2015-10-16 08:22:19.000000000 -0500 +++ nspr/pr/src/misc/prerr.c 2015-11-25 16:32:57.240272706 -0600 @@ -95,3 +95,7 @@ static const struct PRErrorTable et = { void nspr_InitializePRErrorTable(void) { PR_ErrorInstallTable(&et); } + +void nspr_CleanupPRErrorTable(void) { + PR_ErrorRemoveTable(&et); +} --bCsyhTFzCvuiizWE Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="nspr-tpd-memleak.patch" --- nspr/pr/src/threads/prtpd.c.orig 2015-10-16 08:22:19.000000000 -0500 +++ nspr/pr/src/threads/prtpd.c 2015-11-25 17:16:55.078580186 -0600 @@ -72,6 +72,8 @@ void _PR_InitTPD(void) */ void _PR_CleanupTPD(void) { + PR_FREEIF(_pr_tpd_destructors); + _pr_tpd_destructors = NULL; } /* _PR_CleanupTPD */ /* --- nspr/pr/src/pthreads/ptthread.c.orig 2015-10-16 08:22:19.000000000 -0500 +++ nspr/pr/src/pthreads/ptthread.c 2015-11-25 17:43:00.881263152 -0600 @@ -1139,6 +1139,7 @@ PR_IMPLEMENT(PRStatus) PR_Cleanup(void) } PR_DestroyLock(_pr_sleeplock); _pr_sleeplock = NULL; + _PR_CleanupTPD(); _PR_CleanupLayerCache(); _PR_CleanupEnv(); #ifdef _PR_ZONE_ALLOCATOR --bCsyhTFzCvuiizWE Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ dev-tech-nspr mailing list [email protected] https://lists.mozilla.org/listinfo/dev-tech-nspr --bCsyhTFzCvuiizWE--