Commit 1ea4f593 authored by Fabrice Bellard's avatar Fabrice Bellard
Browse files

use av memory handling functions

Originally committed as revision 528 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 06542267
......@@ -431,7 +431,7 @@ static int asf_write_header(AVFormatContext *s)
asf->nb_packets = 0;
if (asf_write_header1(s, 0, 50) < 0) {
free(asf);
av_free(asf);
return -1;
}
......@@ -615,7 +615,7 @@ static int asf_write_trailer(AVFormatContext *s)
put_flush_packet(&s->pb);
free(asf);
av_free(asf);
return 0;
}
......@@ -869,10 +869,10 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
for(i=0;i<s->nb_streams;i++) {
AVStream *st = s->streams[i];
if (st)
free(st->priv_data);
free(st);
av_free(st->priv_data);
av_free(st);
}
free(asf);
av_free(asf);
return -1;
}
......@@ -1009,9 +1009,9 @@ static int asf_read_close(AVFormatContext *s)
for(i=0;i<s->nb_streams;i++) {
AVStream *st = s->streams[i];
free(st->priv_data);
av_free(st->priv_data);
}
free(asf);
av_free(asf);
return 0;
}
......
......@@ -128,7 +128,7 @@ static int au_read_header(AVFormatContext *s,
}
/* now we are ready: build format streams */
st = malloc(sizeof(AVStream));
st = av_malloc(sizeof(AVStream));
if (!st)
return -1;
s->nb_streams = 1;
......
......@@ -161,7 +161,7 @@ static int audio_write_header(AVFormatContext *s1)
s->channels = st->codec.channels;
ret = audio_open(s, 1);
if (ret < 0) {
free(s);
av_free(s);
return -EIO;
} else {
return 0;
......@@ -201,7 +201,7 @@ static int audio_write_trailer(AVFormatContext *s1)
AudioData *s = s1->priv_data;
audio_close(s);
free(s);
av_free(s);
return 0;
}
......@@ -221,7 +221,7 @@ static int audio_read_header(AVFormatContext *s1, AVFormatParameters *ap)
return -ENOMEM;
st = av_mallocz(sizeof(AVStream));
if (!st) {
free(s);
av_free(s);
return -ENOMEM;
}
s1->priv_data = s;
......@@ -232,8 +232,8 @@ static int audio_read_header(AVFormatContext *s1, AVFormatParameters *ap)
ret = audio_open(s, 0);
if (ret < 0) {
free(st);
free(s);
av_free(st);
av_free(s);
return -EIO;
} else {
/* take real parameters */
......@@ -284,7 +284,7 @@ static int audio_read_close(AVFormatContext *s1)
AudioData *s = s1->priv_data;
audio_close(s);
free(s);
av_free(s);
return 0;
}
......
......@@ -142,6 +142,9 @@ extern AVFormat au_format;
/* wav.c */
extern AVFormat wav_format;
/* crc.c */
extern AVFormat crc_format;
/* img.c */
extern AVFormat pgm_format;
extern AVFormat ppm_format;
......
......@@ -54,7 +54,7 @@ int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
int i, bps;
AVStream *st;
avi = malloc(sizeof(AVIContext));
avi = av_malloc(sizeof(AVIContext));
if (!avi)
return -1;
memset(avi, 0, sizeof(AVIContext));
......@@ -106,7 +106,7 @@ int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
s->nb_streams = get_le32(pb);
for(i=0;i<s->nb_streams;i++) {
AVStream *st;
st = malloc(sizeof(AVStream));
st = av_malloc(sizeof(AVStream));
if (!st)
goto fail;
memset(st, 0, sizeof(AVStream));
......@@ -198,8 +198,7 @@ int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
if (stream_index != s->nb_streams - 1) {
fail:
for(i=0;i<s->nb_streams;i++) {
if (s->streams[i])
free(s->streams[i]);
av_freep(&s->streams[i]);
}
return -1;
}
......@@ -248,6 +247,6 @@ int avi_read_packet(AVFormatContext *s, AVPacket *pkt)
int avi_read_close(AVFormatContext *s)
{
AVIContext *avi = s->priv_data;
free(avi);
av_free(avi);
return 0;
}
......@@ -149,7 +149,7 @@ static int avi_write_header(AVFormatContext *s)
AVCodecContext *stream, *video_enc;
offset_t list1, list2, strh, strf;
avi = malloc(sizeof(AVIContext));
avi = av_malloc(sizeof(AVIContext));
if (!avi)
return -1;
memset(avi, 0, sizeof(AVIContext));
......@@ -177,7 +177,7 @@ static int avi_write_header(AVFormatContext *s)
}
if (!video_enc) {
free(avi);
av_free(avi);
return -1;
}
nb_frames = 0;
......@@ -259,7 +259,7 @@ static int avi_write_header(AVFormatContext *s)
break;
case CODEC_TYPE_AUDIO:
if (put_wav_header(pb, stream) < 0) {
free(avi);
av_free(avi);
return -1;
}
break;
......@@ -309,7 +309,7 @@ static int avi_write_packet(AVFormatContext *s, int stream_index,
avi->audio_strm_length[stream_index] += size;
if (!url_is_streamed(&s->pb)) {
idx = malloc(sizeof(AVIIndex));
idx = av_malloc(sizeof(AVIIndex));
memcpy(idx->tag, tag, 4);
idx->flags = flags;
idx->pos = url_ftell(pb) - avi->movi_list;
......@@ -389,7 +389,7 @@ static int avi_write_trailer(AVFormatContext *s)
}
put_flush_packet(pb);
free(avi);
av_free(avi);
return 0;
}
......
......@@ -60,7 +60,7 @@ int url_open(URLContext **puc, const char *filename, int flags)
}
return -ENOENT;
found:
uc = malloc(sizeof(URLContext));
uc = av_malloc(sizeof(URLContext));
if (!uc)
return -ENOMEM;
uc->prot = up;
......@@ -69,7 +69,7 @@ int url_open(URLContext **puc, const char *filename, int flags)
uc->packet_size = 1; /* default packet size */
err = up->url_open(uc, filename, flags);
if (err < 0) {
free(uc);
av_free(uc);
*puc = NULL;
return err;
}
......@@ -118,7 +118,7 @@ int url_close(URLContext *h)
int ret;
ret = h->prot->url_close(h);
free(h);
av_free(h);
return ret;
}
......
......@@ -337,14 +337,14 @@ int url_fdopen(ByteIOContext *s, URLContext *h)
int buffer_size;
buffer_size = (IO_BUFFER_SIZE / h->packet_size) * h->packet_size;
buffer = malloc(buffer_size);
buffer = av_malloc(buffer_size);
if (!buffer)
return -ENOMEM;
if (init_put_byte(s, buffer, buffer_size,
(h->flags & URL_WRONLY) != 0, h,
url_read_packet, url_write_packet, url_seek_packet) < 0) {
free(buffer);
av_free(buffer);
return -EIO;
}
s->is_streamed = h->is_streamed;
......@@ -356,11 +356,11 @@ int url_fdopen(ByteIOContext *s, URLContext *h)
int url_setbufsize(ByteIOContext *s, int buf_size)
{
UINT8 *buffer;
buffer = malloc(buf_size);
buffer = av_malloc(buf_size);
if (!buffer)
return -ENOMEM;
free(s->buffer);
av_free(s->buffer);
s->buffer = buffer;
s->buffer_size = buf_size;
s->buf_ptr = buffer;
......@@ -391,7 +391,7 @@ int url_fclose(ByteIOContext *s)
{
URLContext *h = s->opaque;
free(s->buffer);
av_free(s->buffer);
memset(s, 0, sizeof(ByteIOContext));
return url_close(h);
}
......
......@@ -93,6 +93,7 @@ static int crc_write_trailer(struct AVFormatContext *s)
snprintf(buf, sizeof(buf), "CRC=%08x\n", crc->crcval);
put_buffer(&s->pb, buf, strlen(buf));
put_flush_packet(&s->pb);
av_free(crc);
return 0;
}
......
......@@ -198,10 +198,9 @@ static int ffm_write_header(AVFormatContext *s)
for(i=0;i<s->nb_streams;i++) {
st = s->streams[i];
fst = st->priv_data;
if (fst)
free(fst);
av_free(fst);
}
free(ffm);
av_free(ffm);
return -1;
}
......@@ -252,8 +251,8 @@ static int ffm_write_trailer(AVFormatContext *s)
put_flush_packet(pb);
for(i=0;i<s->nb_streams;i++)
free(s->streams[i]->priv_data);
free(ffm);
av_free(s->streams[i]->priv_data);
av_free(ffm);
return 0;
}
......@@ -433,13 +432,12 @@ static int ffm_read_header(AVFormatContext *s, AVFormatParameters *ap)
st = s->streams[i];
if (st) {
fst = st->priv_data;
if (fst)
free(fst);
free(st);
av_free(fst);
av_free(st);
}
}
if (ffm)
free(ffm);
av_free(ffm);
return -1;
}
......@@ -615,9 +613,9 @@ static int ffm_read_close(AVFormatContext *s)
for(i=0;i<s->nb_streams;i++) {
st = s->streams[i];
free(st->priv_data);
av_free(st->priv_data);
}
free(s->priv_data);
av_free(s->priv_data);
return 0;
}
......
......@@ -202,7 +202,7 @@ static int gif_write_header(AVFormatContext *s)
return -1;
*/
gif = malloc(sizeof(GIFContext));
gif = av_malloc(sizeof(GIFContext));
if (!gif)
return -1;
s->priv_data = gif;
......@@ -218,7 +218,7 @@ static int gif_write_header(AVFormatContext *s)
}
if (!video_enc) {
free(gif);
av_free(gif);
return -1;
} else {
width = video_enc->width;
......@@ -382,7 +382,7 @@ static int gif_write_trailer(AVFormatContext *s)
put_byte(pb, 0x3b);
put_flush_packet(&s->pb);
free(gif);
av_free(gif);
return 0;
}
......
......@@ -67,7 +67,7 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
return -ENOMEM;
st = av_mallocz(sizeof(AVStream));
if (!st) {
free(s);
av_free(s);
return -ENOMEM;
}
s1->priv_data = s;
......@@ -231,8 +231,8 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
fail:
if (video_fd >= 0)
close(video_fd);
free(st);
free(s);
av_free(st);
av_free(s);
return -EIO;
}
......@@ -327,7 +327,7 @@ static int grab_read_close(AVFormatContext *s1)
ioctl(s->fd, VIDIOCSAUDIO, &audio_saved);
close(s->fd);
free(s);
av_free(s);
return 0;
}
......
......@@ -58,7 +58,7 @@ static int http_open(URLContext *h, const char *uri, int flags)
h->is_streamed = 1;
s = malloc(sizeof(HTTPContext));
s = av_malloc(sizeof(HTTPContext));
if (!s) {
return -ENOMEM;
}
......@@ -129,7 +129,7 @@ static int http_open(URLContext *h, const char *uri, int flags)
fail:
if (fd >= 0)
close(fd);
free(s);
av_free(s);
return -EIO;
}
......
......@@ -255,7 +255,7 @@ static int img_read_header(AVFormatContext *s1, AVFormatParameters *ap)
ByteIOContext pb1, *f = &pb1;
AVStream *st;
s = malloc(sizeof(VideoData));
s = av_malloc(sizeof(VideoData));
if (!s)
return -ENOMEM;
......@@ -264,7 +264,7 @@ static int img_read_header(AVFormatContext *s1, AVFormatParameters *ap)
s1->nb_streams = 1;
st = av_mallocz(sizeof(AVStream));
if (!st) {
free(s);
av_free(s);
return -ENOMEM;
}
s1->streams[0] = st;
......@@ -372,14 +372,14 @@ static int img_read_header(AVFormatContext *s1, AVFormatParameters *ap)
if (!s->is_pipe)
url_fclose(f);
fail:
free(s);
av_free(s);
return -EIO;
}
static int img_read_close(AVFormatContext *s1)
{
VideoData *s = s1->priv_data;
free(s);
av_free(s);
return 0;
}
......@@ -510,7 +510,7 @@ static int img_write_header(AVFormatContext *s)
}
return 0;
fail:
free(img);
av_free(img);
return -EIO;
}
......@@ -591,7 +591,7 @@ static int img_write_packet(AVFormatContext *s, int stream_index,
static int img_write_trailer(AVFormatContext *s)
{
VideoData *img = s->priv_data;
free(img);
av_free(img);
return 0;
}
......
......@@ -144,7 +144,7 @@ static int jpeg_write_packet(AVFormatContext *s1, int stream_index,
static int jpeg_write_trailer(AVFormatContext *s1)
{
JpegContext *s = s1->priv_data;
free(s);
av_free(s);
return 0;
}
......@@ -167,7 +167,7 @@ static int jpeg_read_header(AVFormatContext *s1, AVFormatParameters *ap)
s1->nb_streams = 1;
st = av_mallocz(sizeof(AVStream));
if (!st) {
free(s);
av_free(s);
return -ENOMEM;
}
s1->streams[0] = st;
......@@ -193,7 +193,7 @@ static int jpeg_read_header(AVFormatContext *s1, AVFormatParameters *ap)
st->codec.frame_rate = ap->frame_rate;
return 0;
fail:
free(s);
av_free(s);
return -EIO;
}
......@@ -227,7 +227,7 @@ static int jpeg_read_packet(AVFormatContext *s1, AVPacket *pkt)
static int jpeg_read_close(AVFormatContext *s1)
{
JpegContext *s = s1->priv_data;
free(s);
av_free(s);
return 0;
}
......
# Microsoft Developer Studio Project File - Name="libav" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
CFG=libav - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "libav.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "libav.mak" CFG="libav - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "libav - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "libav - Win32 Debug" (based on "Win32 (x86) Static Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "libav - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "../Release/libav"
# PROP Intermediate_Dir "../Release/libav"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /I "../libavcodec" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD BASE RSC /l 0x40c /d "NDEBUG"
# ADD RSC /l 0x40c /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ELSEIF "$(CFG)" == "libav - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "../Debug/libav"
# PROP Intermediate_Dir "../Debug/libav"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../libavcodec" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD BASE RSC /l 0x40c /d "_DEBUG"
# ADD RSC /l 0x40c /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# SUBTRACT LIB32 /nologo
!ENDIF
# Begin Target
# Name "libav - Win32 Release"
# Name "libav - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\asf.c
# End Source File
# Begin Source File
SOURCE=.\avformat.h
# End Source File
# Begin Source File
SOURCE=.\avi.h
# End Source File
# Begin Source File
SOURCE=.\avidec.c
# End Source File
# Begin Source File
SOURCE=.\avienc.c
# End Source File
# Begin Source File
SOURCE=.\avio.c
# End Source File
# Begin Source File
SOURCE=.\avio.h
# End Source File
# Begin Source File
SOURCE=.\aviobuf.c
# End Source File
# Begin Source File
SOURCE=.\file.c
# End Source File
# Begin Source File
SOURCE=.\img.c
# End Source File
# Begin Source File
SOURCE=.\jpegenc.c
# End Source File
# Begin Source File
SOURCE=.\mpeg.c
# End Source File
# Begin Source File
SOURCE=.\raw.c
# End Source File
# Begin Source File
SOURCE=.\rm.c
# End Source File
# Begin Source File
SOURCE=.\swf.c
# End Source File
# Begin Source File
SOURCE=.\utils.c
# End Source File
# Begin Source File
SOURCE=.\wav.c
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# End Group
# End Target
# End Project
......@@ -335,11 +335,11 @@ static int parse_trak(const MOVParseTableEntry *parse_table, ByteIOContext *pb,
#endif