[vlc-devel] Rémi Duraffort : Check the returned values of malloc.

git version control git at videolan.org
Sun Mar 2 14:25:46 CET 2008


Module: vlc
Branch: master
Commit: 3f9cee77afc85efbf1a53329df98b1ac74e1327c
URL:    http://git2.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=3f9cee77afc85efbf1a53329df98b1ac74e1327c

Author: Rémi Duraffort <ivoire at via.ecp.fr>
Date:   Sun Mar  2 13:24:35 2008 +0100

Check the returned values of malloc.

---

 src/modules/modules.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/modules/modules.c b/src/modules/modules.c
index b505d1c..b59d4ce 100644
--- a/src/modules/modules.c
+++ b/src/modules/modules.c
@@ -819,11 +819,20 @@ char ** __module_GetModulesNamesForCapability( vlc_object_t *p_this,
         if( psz_module_capability && !strcmp( psz_module_capability, psz_capability ) )
             count++;
     }
-    /* FIXME: must check the return value and modify the calling functions
-              to test for a NULL : potential segfault */
+
     psz_ret = malloc( sizeof(char*) * (count+1) );
     if( pppsz_longname )
         *pppsz_longname = malloc( sizeof(char*) * (count+1) );
+    if( !psz_ret || ( pppsz_longname && *pppsz_longname == NULL ) )
+    {
+        msg_Err( p_this, "out of memory" );
+        free( psz_ret );
+        free( *pppsz_longname );
+        *pppsz_longname = NULL;
+        vlc_list_release( p_list );
+        return NULL;
+    }
+
     j = 0;
     for( i = 0 ; i < p_list->i_count; i++)
     {




More information about the vlc-devel mailing list