Commit 7c672fe0 authored by vaclav's avatar vaclav
Browse files

add malloc() return errors

parent c9a940af
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1865,9 +1865,9 @@ ivas_error ivas_init_decoder(
     * Allocate and initialize limiter struct
     *-----------------------------------------------------------------*/

    if ( ( st_ivas->hLimiter = ivas_limiter_open( hDecoderConfig->nchan_out, output_Fs ) ) == NULL )
    if ( ( error = ivas_limiter_open( &st_ivas->hLimiter, hDecoderConfig->nchan_out, output_Fs ) ) != IVAS_ERR_OK )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Failed to open limiter handle" );
        return error;
    }

    /*-----------------------------------------------------------------*
+12 −3
Original line number Diff line number Diff line
@@ -109,11 +109,17 @@ ivas_error ivas_dirac_ana_open(
    /* intensity 3-dim */
    for ( i = 0; i < DIRAC_NUM_DIMS; i++ )
    {
        hDirAC->direction_vector_m[i] = (float **) malloc( MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( float * ) );
        if ( ( hDirAC->direction_vector_m[i] = (float **) malloc( MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( float * ) ) ) == NULL )
        {
            return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA decoder\n" ) );
        }

        for ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ )
        {
            hDirAC->direction_vector_m[i][j] = (float *) malloc( MASA_FREQUENCY_BANDS * sizeof( float ) );
            if ( ( hDirAC->direction_vector_m[i][j] = (float *) malloc( MASA_FREQUENCY_BANDS * sizeof( float ) ) ) == NULL )
            {
                return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA decoder\n" ) );
            }
            set_zero( hDirAC->direction_vector_m[i][j], MASA_FREQUENCY_BANDS );
        }
    }
@@ -122,7 +128,10 @@ ivas_error ivas_dirac_ana_open(
    {
        for ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ )
        {
            hDirAC->buffer_intensity_real[i][j] = (float *) malloc( MASA_FREQUENCY_BANDS * sizeof( float ) );
            if ( ( hDirAC->buffer_intensity_real[i][j] = (float *) malloc( MASA_FREQUENCY_BANDS * sizeof( float ) ) ) == NULL )
            {
                return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA decoder\n" ) );
            }
            set_zero( hDirAC->buffer_intensity_real[i][j], MASA_FREQUENCY_BANDS );
        }
    }
+14 −7
Original line number Diff line number Diff line
@@ -101,7 +101,8 @@ static int16_t detect_strong_saturations(
 *-------------------------------------------------------------------*/

/*! r : limiter struct handle */
IVAS_LIMITER_HANDLE ivas_limiter_open(
ivas_error ivas_limiter_open(
    IVAS_LIMITER_HANDLE *hLimiter_out, /* o  : limiter struct handle                           */
    const int16_t max_num_channels,    /* i  : maximum number of I/O channels to be processed  */
    const int32_t sampling_rate        /* i  : sampling rate for processing                    */
)
@@ -111,17 +112,21 @@ IVAS_LIMITER_HANDLE ivas_limiter_open(

    if ( max_num_channels <= 0 || sampling_rate <= 0 )
    {
        return NULL;
        return ( IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Wrong parameters for Limiter\n" ) );
    }

    if ( ( hLimiter = malloc( sizeof( IVAS_LIMITER ) ) ) == NULL )
    {
        return NULL;
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Limiter handle\n" ) );
    }

    hLimiter->max_num_channels = max_num_channels;
    hLimiter->num_channels = max_num_channels;
    hLimiter->channel_ptrs = malloc( max_num_channels * sizeof( float * ) );

    if ( ( hLimiter->channel_ptrs = malloc( max_num_channels * sizeof( float * ) ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Limiter handle\n" ) );
    }
    hLimiter->sampling_rate = sampling_rate;
    hLimiter->gain = 1.f;
    hLimiter->release_heuristic = 0.f;
@@ -136,7 +141,9 @@ IVAS_LIMITER_HANDLE ivas_limiter_open(
        hLimiter->channel_ptrs[i] = NULL;
    }

    return hLimiter;
    *hLimiter_out = hLimiter;

    return IVAS_ERR_OK;
}


+3 −2
Original line number Diff line number Diff line
@@ -80,8 +80,9 @@ void ivas_output_init(
 * Limiter prototypes
 *----------------------------------------------------------------------------------*/

/*! r: limiter struct handle */
IVAS_LIMITER_HANDLE ivas_limiter_open(

ivas_error ivas_limiter_open(
    IVAS_LIMITER_HANDLE *hLimiter_out,                          /* o  : limiter struct handle                   */
    const int16_t num_channels,                                 /* i  : number of I/O channels                  */
    const int32_t sampling_rate                                 /* i  : sampling rate for processing            */
);
+6 −6
Original line number Diff line number Diff line
@@ -790,10 +790,10 @@ static ivas_error initLimiter(
    const int16_t numChannels,
    const int32_t sampleRate )
{
    ivas_error error;

    /* If re-initializing with unchanged values, return early */
    if ( *phLimiter != NULL &&
         ( *phLimiter )->num_channels == numChannels &&
         ( *phLimiter )->sampling_rate == sampleRate )
    if ( *phLimiter != NULL && ( *phLimiter )->num_channels == numChannels && ( *phLimiter )->sampling_rate == sampleRate )
    {
        return IVAS_ERR_OK;
    }
@@ -804,9 +804,9 @@ static ivas_error initLimiter(
        ivas_limiter_close( phLimiter );
    }

    if ( ( *phLimiter = ivas_limiter_open( numChannels, sampleRate ) ) == NULL )
    if ( ( error = ivas_limiter_open( phLimiter, numChannels, sampleRate ) ) != IVAS_ERR_OK )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Failed to open limiter handle" );
        return error;
    }

    return IVAS_ERR_OK;