Open Bug 96122 Opened 23 years ago Updated 2 years ago

memory leak in prlink.c

Categories

(NSPR :: NSPR, defect)

4.1.2
defect

Tracking

(Not tracked)

Future

People

(Reporter: jeff, Unassigned)

References

Details

(Keywords: memory-leak)

Attachments

(1 file, 1 obsolete file)

in nsprpub/pr/src/linking/prlink.c, the routine _PR_ShutdownLinker()
is #ifdef'd WIN16.  The cleanup there is also applicable to WIN32.

consider changing:
<#if defined(WIN16)
>#if defined(WIN16) || defined(WIN32)

also, make the same change in prinit.c around the call to this
function.

you may also want to consider adding the following to 
the bottom of this function:

    if (_pr_currentLibPath)
    {
	PR_Free(_pr_currentLibPath);
	_pr_currentLibPath = NULL;
    }

this is a static leak rather than a per-connection leak.
More memory leak goodness thanks jeff.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Keywords: mlk, patch, review
Blocks: 92580
No longer blocks: 92580
I agree that the cleanup in _PR_ShutdownLinker() is also
applicable to other platforms.	However, I don't think
it is NSPR's responsibility to unload the DLLs for the
application.  Any DLLs loaded by the application via
PR_LoadLibrary should be unloaded by the application via
PR_UnloadLibrary.  Therefore, I left the original
_PR_ShutdownLinker() as is (still ifdef's WIN16) and
wrote a new implementation that destroys the static
data created by NSPR.  This patch is not complete
because I haven't figured out how to destroy
pr_exe_loadmap.

While I was at it, I also fixed the problem that
the allocation and free routines for _pr_currentLibPath
and lib->name were mismatched.	They are now allocated
by either malloc() or strdup() and freed by free().
Comment on attachment 62906 [details] [diff] [review]
Proposed patch.  Incomplete (pr_exe_loadmap is not destroyed)

Checked in this patch into the tip of NSPR.
I just wanted to note that this bug is not fixed until
pr_exe_loadmap has been dealt with.
Status: NEW → ASSIGNED
Priority: -- → P2
Target Milestone: --- → Future
OS: Windows 2000 → All
Hardware: PC → All
clearing keywords to reflect that the patch is in.
Keywords: patch, review
Blocks: 129902
Attachment #62906 - Attachment is obsolete: true
QA Contact: wtchang → nspr
In comment 2, I didn't write down why it's hard to
destroy pr_exe_loadmap.  Now I don't remember what
I thought the issues were.

I just studied all the code that uses pr_exe_loadmap.
The only issue I found is that PR_LoadStaticLibrary
may reference pr_exe_loadmap->dlh:
http://mxr.mozilla.org/nspr/source/nsprpub/pr/src/linking/prlink.c#1613

1611     lm->name = strdup(name);
1612     lm->refCount    = 1;
1613     lm->dlh         = pr_exe_loadmap ? pr_exe_loadmap->dlh : 0; <=== REFERENCE
1614     lm->staticTable = slt;
1615     lm->next        = pr_loadmap;
1616     pr_loadmap      = lm;

So we can destroy pr_exe_loadmap only if no lm on pr_loadmap
has lm->staticTable != NULL and lm->dlh == pr_exe_loadmap->dlh.
Proposed patch to correctly destroy pr_exe_loadmap in PR_ShutdownLinker() (nspr/pr/src/linking/prlink.c)
I found this old bug, and I have a proposed patch that might destroy pr_exe_load_map correctly.

Call PR_UnloadLibrary(pr_exe_loadmap);
and then set it to NULL p_exe_load_map = NULL;

This should bypass the reference in PR_LoadStaticLibrary since it checks for NULL before de-referencing pr_exe_loadmap
hduston, IIUC Wan-Teh's comment 6 means: Unconditionally destroying pr_exe_loadmap, like suggested in your patch, shouldn't be done. Rather, you'd have to verify the conditions described in comment 6 are false, and only then destroy. If true, you'd have to allow it to leak.

The bug assignee didn't login in Bugzilla in the last 7 months and this bug has priority 'P2'.
:KaiE, could you have a look please?
For more information, please visit auto_nag documentation.

Assignee: wtc → nobody
Status: ASSIGNED → NEW
Flags: needinfo?(kaie)
Flags: needinfo?(kaie)
Priority: P2 → --
Severity: minor → S4
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: