Last Comment Bug 440062 - incorrect list element count in PKIX_List_AppendItem function
: incorrect list element count in PKIX_List_AppendItem function
Status: RESOLVED FIXED
PKIX
:
Product: NSS
Classification: Components
Component: Libraries (show other bugs)
: 3.12
: All All
: P2 normal (vote)
: 3.12.1
Assigned To: Alexei Volkov
:
Mentors:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-06-18 11:01 PDT by Alexei Volkov
Modified: 2008-06-23 09:58 PDT (History)
0 users
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---


Attachments
Add new member to the list only upon success. (1.80 KB, patch)
2008-06-18 11:02 PDT, Alexei Volkov
nelson: review+
Details | Diff | Splinter Review

Description Alexei Volkov 2008-06-18 11:01:28 PDT
PKIX_List structure is the single linked list of PKIX_List object. The head structure keeps count of elements in the list.

PKIX_List_AppendItem increments count at the end of function upon success. If PKIX_INCREF(item) returns error, new member(object of PKIX_List structure) will be added to the list, but the count will not be incremented and so the object will be leaked. 

Here is the code:
        lastElement = list;
        for (i = 0; i < length; i++){
                lastElement = lastElement->next;
        }

        PKIX_CHECK(pkix_List_Create_Internal
                    (PKIX_FALSE, &lastElement->next, plContext),
                    PKIX_LISTCREATEINTERNALFAILED);

        PKIX_INCREF(item);
        newElement->item = item;

        PKIX_CHECK(PKIX_PL_Object_InvalidateCache
                    ((PKIX_PL_Object *)list, plContext),
                    PKIX_OBJECTINVALIDATECACHEFAILED);

       list->length = list->length + 1;
Comment 1 Alexei Volkov 2008-06-18 11:02:06 PDT
Created attachment 325592 [details] [diff] [review]
Add new member to the list only upon success.
Comment 2 Nelson Bolyard (seldom reads bugmail) 2008-06-18 11:38:12 PDT
Comment on attachment 325592 [details] [diff] [review]
Add new member to the list only upon success.

r=nelson
Comment 3 Alexei Volkov 2008-06-18 12:59:33 PDT
Patch integrated.

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