Bug 866363: Fix the memory leak of array->items in secitem_FreeArray.
authorWan-Teh Chang <wtc@google.com>
Mon, 29 Apr 2013 18:28:30 -0700
changeset 10748 b3a240eef440582a8a1a13d4fdb65a3e603cfe09
parent 10747 a62f0d35d9aa141ebadd741244578c89cf5dc9ec
child 10749 3986289106f1b63df43e46162764ef1865b06afb
push id58
push userwtc@google.com
push dateTue, 30 Apr 2013 01:28:37 +0000
bugs866363
Bug 866363: Fix the memory leak of array->items in secitem_FreeArray. Mark secitem_FreeArray as static. Don't need to include "base64.h". r=sleevi.
lib/ssl/sslnonce.c
lib/util/secitem.c
--- a/lib/ssl/sslnonce.c
+++ b/lib/ssl/sslnonce.c
@@ -178,20 +178,18 @@ ssl_DestroySID(sslSessionID *sid)
 	PORT_Free((void *)sid->peerID);		/* CONST */
 
     if (sid->urlSvrName != NULL)
 	PORT_Free((void *)sid->urlSvrName);	/* CONST */
 
     if ( sid->peerCert ) {
 	CERT_DestroyCertificate(sid->peerCert);
     }
-    if (sid->peerCertStatus.len) {
+    if (sid->peerCertStatus.items) {
         SECITEM_FreeArray(&sid->peerCertStatus, PR_FALSE);
-        sid->peerCertStatus.items = NULL;
-        sid->peerCertStatus.len = 0;
     }
 
     if ( sid->localCert ) {
 	CERT_DestroyCertificate(sid->localCert);
     }
     if (sid->u.ssl3.sessionTicket.ticket.data) {
 	SECITEM_FreeItem(&sid->u.ssl3.sessionTicket.ticket, PR_FALSE);
     }
--- a/lib/util/secitem.c
+++ b/lib/util/secitem.c
@@ -3,17 +3,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /*
  * Support routines for SECItem data structure.
  */
 
 #include "seccomon.h"
 #include "secitem.h"
-#include "base64.h"
 #include "secerr.h"
 #include "secport.h"
 
 SECItem *
 SECITEM_AllocItem(PRArenaPool *arena, SECItem *item, unsigned int len)
 {
     SECItem *result = NULL;
     void *mark = NULL;
@@ -353,17 +352,18 @@ loser:
         /*
          * If array is not NULL, the above has set array->data and
          * array->len to 0.
          */
     }
     return(NULL);
 }
 
-void secitem_FreeArray(SECItemArray *array, PRBool zero_items, PRBool freeit)
+static void
+secitem_FreeArray(SECItemArray *array, PRBool zero_items, PRBool freeit)
 {
     unsigned int i;
 
     if (!array || !array->len || !array->items)
         return;
 
     for (i=0; i<array->len; ++i) {
         SECItem *item = &array->items[i];
@@ -371,16 +371,19 @@ void secitem_FreeArray(SECItemArray *arr
         if (item->data) {
             if (zero_items) {
                 SECITEM_ZfreeItem(item, PR_FALSE);
             } else {
                 SECITEM_FreeItem(item, PR_FALSE);
             }
         }
     }
+    PORT_Free(array->items);
+    array->items = NULL;
+    array->len = 0;
 
     if (freeit)
         PORT_Free(array);
 }
 
 void SECITEM_FreeArray(SECItemArray *array, PRBool freeit)
 {
     secitem_FreeArray(array, PR_FALSE, freeit);