Bug 586731 jsd_NewSourceText leaks new_url_string ifndef LIVEWIRE
authortimeless@mozdev.org
Mon, 28 Mar 2011 16:49:16 -0400
changeset 64105 473318f3853a0b0963cb7ff5fbacf47d717bca4b
parent 64104 e233ea0e809222ff798c5f9f331018471622c183
child 64106 e54e13ff337a9ea0c3c8c18e91b3759db13b910f
push idunknown
push userunknown
push dateunknown
bugs586731
milestone2.2a1pre
Bug 586731 jsd_NewSourceText leaks new_url_string ifndef LIVEWIRE r=biesi
js/jsd/jsd.h
js/jsd/jsd_text.c
js/jsd/jsdebug.h
--- a/js/jsd/jsd.h
+++ b/js/jsd/jsd.h
@@ -585,17 +585,17 @@ extern JSBool
 jsd_AddFullSourceText(JSDContext* jsdc,
                       const char* text,       /* *not* zero terminated */
                       size_t      length,
                       const char* url);
 
 extern void
 jsd_DestroyAllSources(JSDContext* jsdc);
 
-extern const char*
+extern char*
 jsd_BuildNormalizedURL(const char* url_string);
 
 extern void
 jsd_StartingEvalUsingFilename(JSDContext* jsdc, const char* url);
 
 extern void
 jsd_FinishedEvalUsingFilename(JSDContext* jsdc, const char* url);
 
--- a/js/jsd/jsd_text.c
+++ b/js/jsd/jsd_text.c
@@ -106,23 +106,23 @@ static JSBool
     }
 
     memcpy(jsdsrc->text + jsdsrc->textLength, text, length);
     jsdsrc->textLength += length;
     return JS_TRUE;
 }
 
 static JSDSourceText*
-_newSource(JSDContext* jsdc, const char* url)
+_newSource(JSDContext* jsdc, char* url)
 {
     JSDSourceText* jsdsrc = (JSDSourceText*)calloc(1,sizeof(JSDSourceText));
     if( ! jsdsrc )
         return NULL;
     
-    jsdsrc->url        = (char*) url; /* already a copy */
+    jsdsrc->url        = url;
     jsdsrc->status     = JSD_SOURCE_INITED;
     jsdsrc->dirty      = JS_TRUE;
     jsdsrc->alterCount = jsdc->sourceAlterCount++ ;
             
     return jsdsrc;
 }
 
 static void
@@ -137,17 +137,17 @@ static void
 _removeSource(JSDContext* jsdc, JSDSourceText* jsdsrc)
 {
     JS_REMOVE_LINK(&jsdsrc->links);
     _clearText(jsdc, jsdsrc);
     _destroySource(jsdc, jsdsrc);
 }
 
 static JSDSourceText*
-_addSource(JSDContext* jsdc, const char* url)
+_addSource(JSDContext* jsdc, char* url)
 {
     JSDSourceText* jsdsrc = _newSource(jsdc, url);
     if( ! jsdsrc )
         return NULL;
     JS_INSERT_LINK(&jsdsrc->links, &jsdc->sources);
     return jsdsrc;
 }
 
@@ -208,17 +208,17 @@ strncasecomp (const char* one, const cha
         if (tmp) 
             return tmp;
     }
 }
 
 static char file_url_prefix[]    = "file:";
 #define FILE_URL_PREFIX_LEN     (sizeof file_url_prefix - 1)
 
-const char*
+char*
 jsd_BuildNormalizedURL( const char* url_string )
 {
     char *new_url_string;
 
     if( ! url_string )
         return NULL;
 
     if (!strncasecomp(url_string, file_url_prefix, FILE_URL_PREFIX_LEN) &&
@@ -373,17 +373,17 @@ void DEBUG_ITERATE_SOURCES( JSDContext* 
 #endif
 
 /***************************************************************************/
 
 JSDSourceText*
 jsd_NewSourceText(JSDContext* jsdc, const char* url)
 {
     JSDSourceText* jsdsrc;
-    const char* new_url_string;
+    char* new_url_string;
 
     JSD_LOCK_SOURCE_TEXT(jsdc);
 
 #ifdef LIVEWIRE
     new_url_string = url; /* we take ownership of alloc'd string */
 #else
     new_url_string = jsd_BuildNormalizedURL(url);
 #endif
@@ -391,19 +391,17 @@ jsd_NewSourceText(JSDContext* jsdc, cons
         return NULL;
 
     jsdsrc = jsd_FindSourceForURL(jsdc, new_url_string);
 
     if( jsdsrc )
     {
         if( jsdsrc->doingEval )
         {
-#ifdef LIVEWIRE
-            free((char*)new_url_string);
-#endif
+            free(new_url_string);
             JSD_UNLOCK_SOURCE_TEXT(jsdc);
             return NULL;
         }
         else    
             _moveSourceToRemovedList(jsdc, jsdsrc);
     }
 
     jsdsrc = _addSource( jsdc, new_url_string );
--- a/js/jsd/jsdebug.h
+++ b/js/jsd/jsdebug.h
@@ -658,16 +658,18 @@ extern JSD_PUBLIC_API(void)
 JSD_DestroyAllSources( JSDContext* jsdc );
 
 /* functions for adding source items */
 
 /*
 * Add a new item for a given URL. If an iten already exists for the given URL
 * then the old item is removed.
 * 'url' may not be NULL.
+*
+* ifdef LIVEWIRE url is treated as a char* and ownership is claimed by jsd
 */
 extern JSD_PUBLIC_API(JSDSourceText*)
 JSD_NewSourceText(JSDContext* jsdc, const char* url);
 
 /*
 * Append text (or change status -- e.g. set completed) for a source text
 * item. Text need not be zero terminated. Callers should consider the returned
 * JSDSourceText to be the 'current' item for future use. This may return NULL