]> git.sesse.net Git - vlc/commitdiff
Qt: Avoid using dangling pointers and fix memleaks
authorHugo Beauzée-Luyssen <hugo@beauzee.fr>
Thu, 22 May 2014 09:41:20 +0000 (12:41 +0300)
committerJean-Baptiste Kempf <jb@videolan.org>
Thu, 22 May 2014 10:23:51 +0000 (12:23 +0200)
The pointer returned is only valid for the statement calling the
function. The temporary QByteArray falls out of scope immediatly after

Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
modules/gui/qt4/recents.cpp

index 036dfcca0fcca55765f22458bbe2972f845313f6..8433a1375b081b3a0f4e80d78d161c5386b20434 100644 (file)
@@ -221,7 +221,7 @@ int Open::openMRLwithOptions( intf_thread_t* p_intf,
         for( int j = 0; j < options->count(); j++ ) {
             QString option = colon_unescape( options->at(j) );
             if( !option.isEmpty() ) {
-                ppsz_options[j] = qtu(option);
+                ppsz_options[j] = strdup(qtu(option));
                 i_options++;
             }
         }
@@ -241,7 +241,13 @@ int Open::openMRLwithOptions( intf_thread_t* p_intf,
     if( i_ret == VLC_SUCCESS && b_start && b_playlist )
         RecentsMRL::getInstance( p_intf )->addRecent( mrl );
 
+    /* Free options */
+    if ( ppsz_options != NULL )
+    {
+        for ( int i = 0; i < i_options; ++i )
+            free( (char*)ppsz_options[i] );
+        delete[] ppsz_options;
+    }
     return i_ret;
 }
 
-