Closed Bug 337637 Opened 18 years ago Closed 18 years ago

Memory leak in _MD_OpenSharedMemory (nsprpub/pr/src/md/unix/uxshm.c)

Categories

(NSPR :: NSPR, defect)

All
Linux
defect
Not set
minor

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: kherron+mozilla, Assigned: wtc)

References

()

Details

(Keywords: coverity)

Attachments

(1 file)

This is coverity CID 902. Please see the sample URL. If the allocation at line 100 fails, the allocation at line 92 is leaked.
Attached patch Patch v1Splinter Review
Call PR_DELETE( shm ) before returning NULL in case of a failed malloc for shm->ipcname.
Attachment #237543 - Flags: review?(wtchang)
Comment on attachment 237543 [details] [diff] [review]
Patch v1

r=wtc.  Thanks for the patch.

You can use PR_Free instead of PR_DELETE here.
PR_DELETE is a macro that not only calls PR_Free
but also sets its argument to NULL.  (See
http://lxr.mozilla.org/nspr/ident?i=PR_DELETE)
Since 'shm' is a local variable that is going out
of scope here, it's not necessary to set 'shm' to
NULL after freeing.
Attachment #237543 - Flags: review?(wtchang) → review+
I found that in that function we already use PR_DELETE to free 'shm'.
So it's fine to be consistent.

I checked in the patch on the NSPR trunk (NSPR 4.7) and the
NSPRPUB_PRE_4_2_CLIENT_BRANCH (Mozilla 1.9 alpha).

Checking in uxshm.c;
/cvsroot/mozilla/nsprpub/pr/src/md/unix/uxshm.c,v  <--  uxshm.c
new revision: 3.12; previous revision: 3.11
done

Bugzilla Bug 337637: fixed a memory leak on error in _MD_OpenSharedMemory.
The patch is contributed by Bruno 'Aqualon' Escherl  <aqualon@aquachan.de>.
r=wtc.
Status: NEW → RESOLVED
Closed: 18 years ago
Resolution: --- → FIXED
Target Milestone: --- → 4.7
Checking in uxshm.c;
/cvsroot/mozilla/nsprpub/pr/src/md/unix/uxshm.c,v  <--  uxshm.c
new revision: 3.7.4.5; previous revision: 3.7.4.4
done
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: