Fixes minor issues from the previous allocation wrapper patch

This commit is contained in:
Jean-Marc Valin 2011-08-29 16:10:08 -04:00
parent 07f884042e
commit 85b8e62065
4 changed files with 14 additions and 16 deletions

View file

@ -43,9 +43,6 @@
#ifndef OVERRIDE_CELT_ALLOC
static inline void *opus_alloc (size_t size)
{
/* WARNING: this is not equivalent to malloc(). If you want to use malloc()
or your own allocator, YOU NEED TO CLEAR THE MEMORY ALLOCATED. Otherwise
you will experience strange bugs */
return malloc(size);
}
#endif

View file

@ -132,20 +132,20 @@ failure:
OpusDecoder *opus_decoder_create(int Fs, int channels, int *error)
{
int ret;
char *raw_state = (char*)opus_alloc(opus_decoder_get_size(channels));
if (raw_state == NULL)
OpusDecoder *st = (OpusDecoder *)opus_alloc(opus_decoder_get_size(channels));
if (st == NULL)
{
if (error)
*error = OPUS_ALLOC_FAIL;
return NULL;
}
ret = opus_decoder_init((OpusDecoder*)raw_state, Fs, channels);
ret = opus_decoder_init(st, Fs, channels);
if (ret != OPUS_OK)
{
opus_free(raw_state);
raw_state = NULL;
opus_free(st);
st = NULL;
}
return (OpusDecoder*)raw_state;
return st;
}
static void smooth_fade(const opus_val16 *in1, const opus_val16 *in2, opus_val16 *out,

View file

@ -232,22 +232,22 @@ static unsigned char gen_toc(int mode, int framerate, int bandwidth, int channel
OpusEncoder *opus_encoder_create(int Fs, int channels, int mode, int *error)
{
int ret;
char *raw_state = (char *)opus_alloc(opus_encoder_get_size(channels));
if (raw_state == NULL)
OpusEncoder *st = (OpusEncoder *)opus_alloc(opus_encoder_get_size(channels));
if (st == NULL)
{
if (error)
*error = OPUS_ALLOC_FAIL;
return NULL;
}
ret = opus_encoder_init((OpusEncoder*)raw_state, Fs, channels, mode);
ret = opus_encoder_init(st, Fs, channels, mode);
if (error)
*error = ret;
if (ret != OPUS_OK)
{
opus_free(raw_state);
raw_state = NULL;
opus_free(st);
st = NULL;
}
return (OpusEncoder*)raw_state;
return st;
}
#ifdef FIXED_POINT
int opus_encode(OpusEncoder *st, const opus_val16 *pcm, int frame_size,

View file

@ -33,11 +33,12 @@
#include "opus.h"
#include "opus_private.h"
#include "stack_alloc.h"
#include "stdio.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "float_cast.h"
#include "os_support.h"
typedef struct ChannelLayout {
int nb_channels;