Changeset 3ac440cc8d9a6cc9cfe7443d5e2639ef0a3fa154

Show
Ignore:
Timestamp:
03/10/07 17:35:27 (1 year ago)
Author:
Jean-Paul Saman <jpsaman@videolan.org>
git-committer:
Jean-Paul Saman <jpsaman@videolan.org> 1173544527 +0000
git-parent:

[0bad98632b141f0376b83314f1ea61ab1a27788b]

git-author:
Jean-Paul Saman <jpsaman@videolan.org> 1173544527 +0000
Message:

Fix a bunch of potential memleaks.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/extras/libc.c

    r4f5b5ee r3ac440c  
    9999    len = __MIN( len, n ); 
    100100    psz = (char*)malloc( len + 1 ); 
    101  
    102101    if( psz != NULL ) 
    103102    { 
     
    257256{ 
    258257    double f_result; 
    259     wchar_t *psz_tmp
     258    wchar_t *psz_tmp = NULL
    260259    int i_len = strlen( nptr ) + 1; 
    261260 
    262261    psz_tmp = malloc( i_len * sizeof(wchar_t) ); 
     262    if( !psz_tmp ) 
     263        return NULL; 
    263264    MultiByteToWideChar( CP_ACP, 0, nptr, -1, psz_tmp, i_len ); 
    264265    f_result = wcstod( psz_tmp, NULL ); 
     
    412413void *vlc_wopendir( const wchar_t *wpath ) 
    413414{ 
    414     vlc_DIR *p_dir
    415     _WDIR *p_real_dir
     415    vlc_DIR *p_dir = NULL
     416    _WDIR *p_real_dir = NULL
    416417 
    417418    if ( wpath == NULL || wpath[0] == '\0' 
     
    420421        /* Special mode to list drive letters */ 
    421422        p_dir = malloc( sizeof(vlc_DIR) ); 
     423        if( !p_dir ) 
     424            return NULL; 
    422425        p_dir->p_real_dir = NULL; 
    423426        p_dir->i_drives = GetLogicalDrives(); 
     
    430433 
    431434    p_dir = malloc( sizeof(vlc_DIR) ); 
     435    if( !p_dir ) 
     436    { 
     437        _wclosedir( p_real_dir ); 
     438        return NULL; 
     439    } 
    432440    p_dir->p_real_dir = p_real_dir; 
    433441 
     
    552560        size = sizeof( struct dirent ) + strlen( p_content->d_name ) + 1; 
    553561        pp_list[ret] = malloc( size ); 
    554         memcpy( pp_list[ret], p_content, size ); 
    555         ret++; 
     562        if( pp_list[ret] ) 
     563        { 
     564            memcpy( pp_list[ret], p_content, size ); 
     565            ret++; 
     566        } 
     567        else 
     568        { 
     569            /* Continuing is useless when no more memory can be allocted, 
     570             * so better return what we have found. 
     571             */ 
     572            ret = -1; 
     573            break; 
     574        } 
    556575    } 
    557576 
     
    938957 
    939958    *pi_data = 0; 
     959    if( *pp_data ) 
     960        free( *pp_data ); 
     961    *pp_data = NULL; 
    940962    *pp_data = malloc( 1025 );  /* +1 for \0 */ 
     963    if( !*pp_data ) 
     964        return -1; 
    941965 
    942966    while ( !p_object->b_die ) 
     
    10221046    HANDLE hChildStdinRd, hChildStdinWr, hChildStdoutRd, hChildStdoutWr; 
    10231047    DWORD i_status; 
    1024     char *psz_cmd, *p_env, *p
     1048    char *psz_cmd = NULL, *p_env = NULL, *p = NULL
    10251049    char **ppsz_parser; 
    10261050    int i_size; 
     
    10651089    /* Set up the command line. */ 
    10661090    psz_cmd = malloc(32768); 
     1091    if( !psz_cmd ) 
     1092        return -1; 
    10671093    psz_cmd[0] = '\0'; 
    10681094    i_size = 32768; 
     
    10921118    /* Set up the environment. */ 
    10931119    p = p_env = malloc(32768); 
     1120    if( !p ) 
     1121    { 
     1122        free( psz_cmd ); 
     1123        return -1; 
     1124    } 
     1125 
    10941126    i_size = 32768; 
    10951127    ppsz_parser = &ppsz_env[0]; 
     
    11441176    /* Read output from the child process. */ 
    11451177    *pi_data = 0; 
     1178    if( *pp_data ) 
     1179        free( pp_data ); 
     1180    *pp_data = NULL; 
    11461181    *pp_data = malloc( 1025 );  /* +1 for \0 */ 
    11471182 
     
    11771212 
    11781213    (*pp_data)[*pi_data] = '\0'; 
    1179  
    11801214    return 0; 
    11811215}