[vlc-devel] [PATCH] consistently use malloc()/free() for C-style strings

Justus Piater Justus-bulk at Piater.name
Thu Sep 18 10:11:22 CEST 2008


From: Justus Piater <Justus-dev at Piater.name>

There was a mix of new/delete, malloc()/free() and even several
malloc()/delete, so this fixes actual bugs.
---
 projects/mozilla/control/npolibvlc.cpp  |   24 ++++++++++++------------
 projects/mozilla/control/nporuntime.cpp |    2 +-
 projects/mozilla/vlcplugin.cpp          |   12 ++++++------
 3 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/projects/mozilla/control/npolibvlc.cpp b/projects/mozilla/control/npolibvlc.cpp
index 3084d3e..7c0f7e9 100644
--- a/projects/mozilla/control/npolibvlc.cpp
+++ b/projects/mozilla/control/npolibvlc.cpp
@@ -1423,7 +1423,7 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
                     {
                         url = p_plugin->getAbsoluteURL(s);
                         if( url )
-                            delete s;
+			    free(s);
                         else
                             // problem with combining url, use argument
                             url = s;
@@ -1449,7 +1449,7 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
                     }
                     else
                     {
-                        delete url;
+		        free(url);
                         return INVOKERESULT_INVALID_VALUE;
                     }
                 }
@@ -1475,8 +1475,8 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
                     }
                     else
                     {
-                        delete url;
-                        delete name;
+		        free(url);
+                        free(name);
                         return INVOKERESULT_INVALID_VALUE;
                     }
                 }
@@ -1487,13 +1487,13 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
                                                         i_options,
                                                         const_cast<const char **>(ppsz_options),
                                                         &ex);
-                delete url;
-                delete name;
+                free(url);
+                free(name);
                 for( int i=0; i< i_options; ++i )
                 {
-                    delete ppsz_options[i];
+		    free(ppsz_options[i]);
                 }
-                delete ppsz_options;
+                free(ppsz_options);
 
                 if( libvlc_exception_raised(&ex) )
                 {
@@ -1695,7 +1695,7 @@ void LibvlcPlaylistNPObject::parseOptions(const NPString &nps, int *i_options, c
                             if( ! moreOptions )
                             {
                                 /* failed to allocate more memory */
-                                delete s;
+			        free(s);
                                 /* return what we got so far */
                                 *i_options = nOptions;
                                 *ppsz_options = options;
@@ -1713,7 +1713,7 @@ void LibvlcPlaylistNPObject::parseOptions(const NPString &nps, int *i_options, c
                 *i_options = nOptions;
                 *ppsz_options = options;
             }
-            delete s;
+            free(s);
         }
     }
 }
@@ -1985,7 +1985,7 @@ RuntimeNPObject::InvokeResult LibvlcVideoNPObject::setProperty(int index, const
                 }
 
                 libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex);
-                delete psz_aspect;
+                free(psz_aspect);
                 libvlc_media_player_release(p_md);
 
                 if( libvlc_exception_raised(&ex) )
@@ -2032,7 +2032,7 @@ RuntimeNPObject::InvokeResult LibvlcVideoNPObject::setProperty(int index, const
                 }
 
                 libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex);
-                delete psz_geometry;
+                free(psz_geometry);
                 libvlc_media_player_release(p_md);
 
                 if( libvlc_exception_raised(&ex) )
diff --git a/projects/mozilla/control/nporuntime.cpp b/projects/mozilla/control/nporuntime.cpp
index 57d0769..db9e9a5 100644
--- a/projects/mozilla/control/nporuntime.cpp
+++ b/projects/mozilla/control/nporuntime.cpp
@@ -37,7 +37,7 @@
 
 char* RuntimeNPObject::stringValue(const NPString &s)
 {
-    NPUTF8 *val = new NPUTF8[s.utf8length+1];
+    NPUTF8 *val = static_cast<NPUTF8*>(malloc((s.utf8length+1) * sizeof(*val)));
     if( val )
     {
         strncpy(val, s.utf8characters, s.utf8length);
diff --git a/projects/mozilla/vlcplugin.cpp b/projects/mozilla/vlcplugin.cpp
index e1bd8ef..ec52f29 100644
--- a/projects/mozilla/vlcplugin.cpp
+++ b/projects/mozilla/vlcplugin.cpp
@@ -82,7 +82,7 @@ static bool boolValue(const char *value) {
 NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
 {
     /* prepare VLC command line */
-    char *ppsz_argv[32];
+    const char *ppsz_argv[32];
     int ppsz_argc = 0;
 
     /* locate VLC module path */
@@ -218,7 +218,7 @@ NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
             {
                 NPString &location = NPVARIANT_TO_STRING(result);
 
-                psz_baseURL = new char[location.utf8length+1];
+                psz_baseURL = static_cast<char*>(malloc(location.utf8length+1));
                 if( psz_baseURL )
                 {
                     strncpy(psz_baseURL, location.utf8characters, location.utf8length);
@@ -246,8 +246,8 @@ NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
 
 VlcPlugin::~VlcPlugin()
 {
-    delete[] psz_baseURL;
-    delete psz_target;
+    free(psz_baseURL);
+    free(psz_target);
     if( libvlc_log )
         libvlc_log_close(libvlc_log, NULL);
     if( libvlc_instance )
@@ -295,7 +295,7 @@ relativeurl:
         if( psz_baseURL )
         {
             size_t baseLen = strlen(psz_baseURL);
-            char *href = new char[baseLen+strlen(url)+1];
+            char *href = static_cast<char*>(malloc(baseLen+strlen(url)+1));
             if( href )
             {
                 /* prepend base URL */
@@ -340,7 +340,7 @@ relativeurl:
                     if( '/' != *href )
                     {
                         /* baseURL is not an absolute path */
-                        delete[] href;
+		        free(href);
                         return NULL;
                     }
                     pathstart = href;
-- 
1.5.6.5




More information about the vlc-devel mailing list