[vlc-commits] Qt: Avoid using dangling pointers and fix memleaks

Hugo Beauzée-Luyssen git at videolan.org
Thu May 22 12:32:47 CEST 2014


vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Thu May 22 12:41:20 2014 +0300| [1dc8bb493e6e1a4e78131aea4c9f369330dec25e] | committer: Jean-Baptiste Kempf

Qt: Avoid using dangling pointers and fix memleaks

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 at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=1dc8bb493e6e1a4e78131aea4c9f369330dec25e
---

 modules/gui/qt4/recents.cpp |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/modules/gui/qt4/recents.cpp b/modules/gui/qt4/recents.cpp
index 036dfcc..8433a13 100644
--- a/modules/gui/qt4/recents.cpp
+++ b/modules/gui/qt4/recents.cpp
@@ -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;
 }
 
-



More information about the vlc-commits mailing list