Open Bug 1225123 Opened 9 years ago Updated 2 years ago

memory leak in pk11mode

Categories

(NSS :: Libraries, defect, P3)

Tracking

(Not tracked)

People

(Reporter: vinit.j, Unassigned)

Details

(Keywords: good-first-bug, memory-leak, Whiteboard: [MemShrink:P3])

Attachments

(3 files)

User Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36 Steps to reproduce: There is a memory leak in File: nss/cmd/pk11mode/pk11mode.c +3587 I catch this issues while code review. Actual results: memory to var "pTemplate" has been assigned using calloc as line no. 3560 pTemplate = (CK_ATTRIBUTE_PTR)calloc(number_of_all_known_attribute_types, sizeof(CK_ATTRIBUTE)); At line no. 3587 function is returning without freeing this memory. Expected results: Memory must be freed in this case. As at a very first step crv = pFunctionList->C_FindObjects(h, &o, 1, &nObjects); if ( CKR_OK != crv ) { PKM_Error( "C_FindObjects(%lu, , 1, ) returned 0x%08X, %-26s\n", h, crv, PKM_CK_RVtoStr(crv)); return crv; } if this call falls will leak the allocated memory. I am attaching the fixed patch for this issue.
Keywords: mlk
OS: Unspecified → All
Hardware: Unspecified → All
Attachment #8687935 - Attachment is patch: true
Attachment #8687935 - Attachment mime type: text/x-patch → text/plain
Comment on attachment 8687935 [details] [diff] [review] pk11mode_mlk.patch Review of attachment 8687935 [details] [diff] [review]: ----------------------------------------------------------------- ::: nss_org/cmd/pk11mode/pk11mode.c @@ +3584,4 @@ > if ( CKR_OK != crv ) { > PKM_Error( "C_FindObjects(%lu, , 1, ) returned 0x%08X, %-26s\n", > h, crv, PKM_CK_RVtoStr(crv)); > + free(pTemplate); Vinit, Thank you for the patch. Every return statement after we have allocated pTemplate successfully will need to free pTemplate. So this patch needs more work. Also, the variable pT2 has a similar leak. pT2 is freed at the end of the while loop, but not at other return statements inside the while loop. When you write the full fix, please carefully check every return statement after the variable in question is successfully allocated.
Attachment #8687935 - Flags: review-
Keywords: good-first-bug
Priority: -- → P3
Hello. May I work on this issue?
QA Contact: jjones
Whiteboard: [MemShrink]
Whiteboard: [MemShrink] → [MemShrink:P3]
Severity: normal → S3
Attached patch pk11mode.patchSplinter Review

Seems like memory leakage with pTemplate and pT2 not fixed yet.
I've made a patch that should fix this issue

Attachment #9335830 - Flags: review+

Do you mind submitting the patch using Phabricator? phabricator.services.mozilla.com/

Do you need any help with it?

(In reply to nkulatova from comment #4)

Do you mind submitting the patch using Phabricator? phabricator.services.mozilla.com/

Do you need any help with it?

This is my first contribution so I didn't know that Phabricator should be used.
Uploaded my changes.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: