Closed Bug 679614 Opened 13 years ago Closed 13 years ago

memory leak in symkeyutil.c

Categories

(NSS :: Tools, defect, P2)

defect

Tracking

(Not tracked)

RESOLVED FIXED
3.13.4

People

(Reporter: david.volgyes, Assigned: atulagrwl)

References

Details

Attachments

(1 file, 1 obsolete file)

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:6.0) Gecko/20100101 Firefox/6.0 Build ID: 20110812233755 Steps to reproduce: cppcheck found a memory leak in security/nss/cmd/symkeyutil/symkeyutil.c at line #753. Actual results: A string is allocated in line 753: certPrefix = strdup(symKeyUtil.options[opt_dbPrefix].arg); but there are several exist points below, and the memory is not released there. Expected results: You should free the memory, when it is not necessary anymore.
Blocks: cppcheck
Assignee: nobody → nobody
Component: General → Tools
Product: Firefox → NSS
QA Contact: general → tools
Version: Trunk → trunk
Attached patch v1 patch to free char array memory (obsolete) (deleted) — Splinter Review
Wan-Teh, please assign the review to another person if you are busy.
Attachment #556400 - Flags: review?(wtc)
Whiteboard: [MemShrink]
Status: UNCONFIRMED → NEW
Ever confirmed: true
Assignee: nobody → atulagrwl
I believe that this code is a tool which runs during our build process and it's not in code shipped inside of Firefox, so it is outside of the scope of the MemShrink project.
Whiteboard: [MemShrink]
Attachment #556400 - Flags: review?(rrelyea)
Attachment #556400 - Flags: review?(kaie+oldbugzilla)
Attachment #556400 - Flags: review?(kaie+oldbugzilla) → review?(kaie)
Remainder for code review.
Comment on attachment 556400 [details] [diff] [review] v1 patch to free char array memory r- First, this code isn't in a library, it's in a little utility that will only ever run for a very short amount of time, therefore the programmer probably didn't worry too much about leaks. Therefore I think the approach to add widespread cleanup code is extreme. We should find a simpler solution because certPrefix is only used once. I believe the original programmer simply wanted a "shortcut variable name", instead of having to type that long statement twice. As we can see in the code, arguments like "symKeyUtil.options[opt_TokenName].arg" are used all over the file, so it's not strictly necessary to duplicate that string. I suspect the programmer was playing safe, because the argument certPrefix is passed twice to the init function, and he was worried that something might go wrong. But as far as I can tell, the init function will not keep the string. It will simply use it for the durating of the function call, and then it's no longer required. Ok, here is my proposal for a better change: - remove the call to strdup, in other words change certPrefix = strdup(symKeyUtil.options[opt_dbPrefix].arg); to certPrefix = symKeyUtil.options[opt_dbPrefix].arg; (this simply produce an alias pointer, without allocation) - and keep everything else in its original state
Attachment #556400 - Flags: review?(wtc)
Attachment #556400 - Flags: review?(rrelyea)
Attachment #556400 - Flags: review?(kaie)
Attachment #556400 - Flags: review-
Attached patch Patch v1.1 (deleted) — Splinter Review
Totally agreed. Fixing as suggested.
Attachment #556400 - Attachment is obsolete: true
Attachment #606560 - Flags: review?(kaie)
Comment on attachment 606560 [details] [diff] [review] Patch v1.1 r=kaie
Attachment #606560 - Flags: review?(kaie) → review+
Keywords: checkin-needed
Checking in security/nss/cmd/symkeyutil/symkeyutil.c; /cvsroot/mozilla/security/nss/cmd/symkeyutil/symkeyutil.c,v <-- symkeyutil.c new revision: 1.14; previous revision: 1.13 done
Keywords: checkin-needed
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
OS: Linux → All
Priority: -- → P2
Hardware: x86_64 → All
Target Milestone: --- → 3.13.4
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: