Bug 505108: Don't leak strings on early returns from Area::ParseCoords(), fix how CString is freed. r=roc
authorRandell Jesup <rjesup@wgate.com>
Sat, 11 Jun 2011 16:40:39 -0400
changeset 71440 11b4b4c73f36771df3d1e27d33959829bb22057e
parent 71439 3c4b12d057ef1b2c5c401c76867823173f63244b
child 71441 79394c301944bb391f8d34a7bc8bad1eceb7afee
child 71450 47854e3787ba838835b31436af35cc2e4e12675d
push id159
push usereakhgari@mozilla.com
push dateTue, 16 Aug 2011 17:53:11 +0000
treeherdermozilla-beta@8786e3e49240 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs505108
milestone7.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 505108: Don't leak strings on early returns from Area::ParseCoords(), fix how CString is freed. r=roc
layout/generic/nsImageMap.cpp
--- a/layout/generic/nsImageMap.cpp
+++ b/layout/generic/nsImageMap.cpp
@@ -146,29 +146,31 @@ void Area::ParseCoords(const nsAString& 
 
     /*
      * Nothing in an empty list
      */
     mNumCoords = 0;
     mCoords = nsnull;
     if (*cp == '\0')
     {
+      nsMemory::Free(cp);
       return;
     }
 
     /*
      * Skip beginning whitespace, all whitespace is empty list.
      */
     n_str = cp;
     while (is_space(*n_str))
     {
       n_str++;
     }
     if (*n_str == '\0')
     {
+      nsMemory::Free(cp);
       return;
     }
 
     /*
      * Make a pass where any two numbers separated by just whitespace
      * are given a comma separator.  Count entries while passing.
      */
     cnt = 0;
@@ -243,16 +245,17 @@ void Area::ParseCoords(const nsAString& 
     cnt++;
 
     /*
      * Allocate space for the coordinate array.
      */
     value_list = new nscoord[cnt];
     if (!value_list)
     {
+      nsMemory::Free(cp);
       return;
     }
 
     /*
      * Second pass to copy integer values into list.
      */
     tptr = cp;
     for (i=0; i<cnt; i++)
@@ -285,17 +288,17 @@ void Area::ParseCoords(const nsAString& 
         *ptr = ',';
         tptr = ptr + 1;
       }
     }
 
     mNumCoords = cnt;
     mCoords = value_list;
 
-    NS_Free(cp);
+    nsMemory::Free(cp);
   }
 }
 
 void Area::HasFocus(PRBool aHasFocus)
 {
   mHasFocus = aHasFocus;
 }