summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty <xiphmont@xiph.org>2000-03-10 13:21:18 +0000
committerMonty <xiphmont@xiph.org>2000-03-10 13:21:18 +0000
commitf894be654bb8b1a79e7a49cecdb8580064f831f1 (patch)
tree1874a2a2107c21f69ca66731eba98557a0062926
parent83abb6a7aa99a79b762acca2a9451a50d8b64383 (diff)
downloadlibvorbis-git-f894be654bb8b1a79e7a49cecdb8580064f831f1.tar.gz
Repaired 'I must have been boozing' memory management in vorbisfile.a
Cleaned up every known memory leak (with the help of a malloc tracker, see lib/misc.c and lib/misc.h for details). Monty svn path=/trunk/vorbis/; revision=276
-rw-r--r--examples/chaining_example.c3
-rw-r--r--lib/analysis.c3
-rw-r--r--lib/bitwise.c3
-rw-r--r--lib/block.c20
-rw-r--r--lib/codebook.c3
-rw-r--r--lib/envelope.c3
-rw-r--r--lib/floor0.c3
-rw-r--r--lib/framing.c3
-rw-r--r--lib/info.c3
-rw-r--r--lib/lsp.c3
-rw-r--r--lib/mdct.c3
-rw-r--r--lib/misc.h20
-rw-r--r--lib/psy.c3
-rw-r--r--lib/registry.c3
-rw-r--r--lib/smallft.c3
-rw-r--r--lib/time0.c3
-rw-r--r--lib/vorbisfile.c48
-rw-r--r--lib/window.c3
18 files changed, 86 insertions, 47 deletions
diff --git a/examples/chaining_example.c b/examples/chaining_example.c
index 582ed7f6..632eaeef 100644
--- a/examples/chaining_example.c
+++ b/examples/chaining_example.c
@@ -12,12 +12,13 @@
********************************************************************
function: illustrate simple use of chained bitstream and vorbisfile.a
- last mod: $Id: chaining_example.c,v 1.3 2000/01/05 03:10:24 xiphmont Exp $
+ last mod: $Id: chaining_example.c,v 1.4 2000/03/10 13:21:18 xiphmont Exp $
********************************************************************/
#include "vorbis/codec.h"
#include "vorbis/vorbisfile.h"
+#include "../lib/misc.h"
int main(){
OggVorbis_File ov;
diff --git a/lib/analysis.c b/lib/analysis.c
index f25f4517..ba0c31be 100644
--- a/lib/analysis.c
+++ b/lib/analysis.c
@@ -12,7 +12,7 @@
********************************************************************
function: single-block PCM analysis mode dispatch
- last mod: $Id: analysis.c,v 1.24 2000/02/23 09:24:21 xiphmont Exp $
+ last mod: $Id: analysis.c,v 1.25 2000/03/10 13:21:18 xiphmont Exp $
********************************************************************/
@@ -22,6 +22,7 @@
#include "vorbis/codec.h"
#include "bitwise.h"
#include "registry.h"
+#include "misc.h"
/* decides between modes, dispatches to the appropriate mapping. */
int vorbis_analysis(vorbis_block *vb,ogg_packet *op){
diff --git a/lib/bitwise.c b/lib/bitwise.c
index 821647f6..c11fc46b 100644
--- a/lib/bitwise.c
+++ b/lib/bitwise.c
@@ -12,7 +12,7 @@
********************************************************************
function: packing variable sized words into an octet stream
- last mod: $Id: bitwise.c,v 1.9 2000/02/23 09:24:22 xiphmont Exp $
+ last mod: $Id: bitwise.c,v 1.10 2000/03/10 13:21:18 xiphmont Exp $
********************************************************************/
@@ -22,6 +22,7 @@
#include <string.h>
#include <stdlib.h>
#include "bitwise.h"
+#include "misc.h"
#define BUFFER_INCREMENT 256
diff --git a/lib/block.c b/lib/block.c
index 4728d7ff..c53fe72f 100644
--- a/lib/block.c
+++ b/lib/block.c
@@ -12,7 +12,7 @@
********************************************************************
function: PCM data vector blocking, windowing and dis/reassembly
- last mod: $Id: block.c,v 1.27 2000/02/23 11:22:43 xiphmont Exp $
+ last mod: $Id: block.c,v 1.28 2000/03/10 13:21:18 xiphmont Exp $
Handle windowing, overlap-add, etc of the PCM vectors. This is made
more amusing by Vorbis' current two allowed block sizes.
@@ -35,6 +35,7 @@
#include "bitwise.h"
#include "registry.h"
#include "bookinternal.h"
+#include "misc.h"
static int ilog2(unsigned int v){
int ret=0;
@@ -268,14 +269,19 @@ void vorbis_dsp_clear(vorbis_dsp_state *v){
if(v){
vorbis_info *vi=v->vi;
- if(v->window[0][0][0])
- for(i=0;i<VI_WINDOWB;i++){
+ if(v->window[0][0][0]){
+ for(i=0;i<VI_WINDOWB;i++)
if(v->window[0][0][0][i])free(v->window[0][0][0][i]);
- for(j=0;j<2;j++)
- for(k=0;k<2;k++)
+ free(v->window[0][0][0]);
+
+ for(j=0;j<2;j++)
+ for(k=0;k<2;k++){
+ for(i=0;i<VI_WINDOWB;i++)
if(v->window[1][j][k][i])free(v->window[1][j][k][i]);
- }
-
+ free(v->window[1][j][k]);
+ }
+ }
+
if(v->pcm){
for(i=0;i<vi->channels;i++)
if(v->pcm[i])free(v->pcm[i]);
diff --git a/lib/codebook.c b/lib/codebook.c
index cb45348d..db614705 100644
--- a/lib/codebook.c
+++ b/lib/codebook.c
@@ -12,7 +12,7 @@
********************************************************************
function: basic codebook pack/unpack/code/decode operations
- last mod: $Id: codebook.c,v 1.11 2000/02/23 09:24:26 xiphmont Exp $
+ last mod: $Id: codebook.c,v 1.12 2000/03/10 13:21:18 xiphmont Exp $
********************************************************************/
@@ -22,6 +22,7 @@
#include "vorbis/codebook.h"
#include "bitwise.h"
#include "bookinternal.h"
+#include "misc.h"
/**** pack/unpack helpers ******************************************/
static int ilog(unsigned int v){
diff --git a/lib/envelope.c b/lib/envelope.c
index 6d076405..a66b23a6 100644
--- a/lib/envelope.c
+++ b/lib/envelope.c
@@ -12,7 +12,7 @@
********************************************************************
function: PCM data envelope analysis and manipulation
- last mod: $Id: envelope.c,v 1.15 2000/02/07 20:03:16 xiphmont Exp $
+ last mod: $Id: envelope.c,v 1.16 2000/03/10 13:21:18 xiphmont Exp $
Preecho calculation.
@@ -29,6 +29,7 @@
#include "envelope.h"
#include "bitwise.h"
#include "window.h"
+#include "misc.h"
void _ve_envelope_init(envelope_lookup *e,int samples_per){
int i;
diff --git a/lib/floor0.c b/lib/floor0.c
index 95bf4822..fb9e1bad 100644
--- a/lib/floor0.c
+++ b/lib/floor0.c
@@ -12,7 +12,7 @@
********************************************************************
function: floor backend 0 implementation
- last mod: $Id: floor0.c,v 1.11 2000/02/23 11:22:44 xiphmont Exp $
+ last mod: $Id: floor0.c,v 1.12 2000/03/10 13:21:18 xiphmont Exp $
********************************************************************/
@@ -26,6 +26,7 @@
#include "lsp.h"
#include "bookinternal.h"
#include "scales.h"
+#include "misc.h"
typedef struct {
long n;
diff --git a/lib/framing.c b/lib/framing.c
index 30fe802b..b2ca7191 100644
--- a/lib/framing.c
+++ b/lib/framing.c
@@ -13,7 +13,7 @@
function: code raw [Vorbis] packets into framed OggSquish stream and
decode Ogg streams back into raw packets
- last mod: $Id: framing.c,v 1.14 2000/01/12 11:34:40 xiphmont Exp $
+ last mod: $Id: framing.c,v 1.15 2000/03/10 13:21:18 xiphmont Exp $
note: The CRC code is directly derived from public domain code by
Ross Williams (ross@guest.adelaide.edu.au). See docs/framing.html
@@ -24,6 +24,7 @@
#include <stdlib.h>
#include <string.h>
#include "vorbis/codec.h"
+#include "misc.h"
/* A complete description of Ogg framing exists in docs/framing.html */
diff --git a/lib/info.c b/lib/info.c
index 0b5fd022..c73cb02f 100644
--- a/lib/info.c
+++ b/lib/info.c
@@ -12,7 +12,7 @@
********************************************************************
function: maintain the info structure, info <-> header packets
- last mod: $Id: info.c,v 1.22 2000/02/23 11:50:29 xiphmont Exp $
+ last mod: $Id: info.c,v 1.23 2000/03/10 13:21:18 xiphmont Exp $
********************************************************************/
@@ -28,6 +28,7 @@
#include "registry.h"
#include "window.h"
#include "psy.h"
+#include "misc.h"
/* helpers */
static int ilog2(unsigned int v){
diff --git a/lib/lsp.c b/lib/lsp.c
index f536ee16..a893d32d 100644
--- a/lib/lsp.c
+++ b/lib/lsp.c
@@ -12,7 +12,7 @@
********************************************************************
function: LSP (also called LSF) conversion routines
- last mod: $Id: lsp.c,v 1.4 1999/12/30 07:26:42 xiphmont Exp $
+ last mod: $Id: lsp.c,v 1.5 2000/03/10 13:21:18 xiphmont Exp $
The LSP generation code is taken (with minimal modification) from
"On the Computation of the LSP Frequencies" by Joseph Rothweiler
@@ -26,6 +26,7 @@
#include <string.h>
#include <stdlib.h>
#include "os.h"
+#include "misc.h"
void vorbis_lsp_to_lpc(double *lsp,double *lpc,int m){
int i,j,m2=m/2;
diff --git a/lib/mdct.c b/lib/mdct.c
index a3cccedb..1b1d195e 100644
--- a/lib/mdct.c
+++ b/lib/mdct.c
@@ -13,7 +13,7 @@
function: normalized modified discrete cosine transform
power of two length transform only [16 <= n ]
- last mod: $Id: mdct.c,v 1.15 2000/02/09 22:04:15 xiphmont Exp $
+ last mod: $Id: mdct.c,v 1.16 2000/03/10 13:21:18 xiphmont Exp $
Algorithm adapted from _The use of multirate filter banks for coding
of high quality digital audio_, by T. Sporer, K. Brandenburg and
@@ -39,6 +39,7 @@
#include <math.h>
#include "mdct.h"
#include "os.h"
+#include "misc.h"
/* build lookups for trig functions; also pre-figure scaling and
some window function algebra. */
diff --git a/lib/misc.h b/lib/misc.h
index bae284fa..7a4ae1b0 100644
--- a/lib/misc.h
+++ b/lib/misc.h
@@ -12,15 +12,33 @@
********************************************************************
function: miscellaneous prototypes
- last mod: $Id: misc.h,v 1.2 2000/02/23 09:24:30 xiphmont Exp $
+ last mod: $Id: misc.h,v 1.3 2000/03/10 13:21:18 xiphmont Exp $
********************************************************************/
#ifndef _V_RANDOM_H_
#define _V_RANDOM_H_
+#include "vorbis/codec.h"
extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
extern void _vorbis_block_ripcord(vorbis_block *vb);
extern void _analysis_output(char *base,int i,double *v,int n);
+#ifdef DEBUG_LEAKS
+extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line);
+extern void _VDBG_free(void *ptr,char *file,long line);
+
+#ifndef MISC_C
+#undef malloc
+#undef calloc
+#undef realloc
+#undef free
+
+#define malloc(x) _VDBG_malloc(NULL,(x),__FILE__,__LINE__)
+#define calloc(x,y) _VDBG_malloc(NULL,(x)*(y),__FILE__,__LINE__)
+#define realloc(x,y) _VDBG_malloc((x),(y),__FILE__,__LINE__)
+#define free(x) _VDBG_free((x),__FILE__,__LINE__)
+#endif
+#endif
+
#endif
diff --git a/lib/psy.c b/lib/psy.c
index dd6a10ed..9ba5d219 100644
--- a/lib/psy.c
+++ b/lib/psy.c
@@ -12,7 +12,7 @@
********************************************************************
function: psychoacoustics not including preecho
- last mod: $Id: psy.c,v 1.16 2000/02/12 08:33:07 xiphmont Exp $
+ last mod: $Id: psy.c,v 1.17 2000/03/10 13:21:18 xiphmont Exp $
********************************************************************/
@@ -26,6 +26,7 @@
#include "lpc.h"
#include "smallft.h"
#include "scales.h"
+#include "misc.h"
/* Set up decibel threshhold slopes on a Bark frequency scale */
diff --git a/lib/registry.c b/lib/registry.c
index 4264c79d..8e3d6611 100644
--- a/lib/registry.c
+++ b/lib/registry.c
@@ -12,12 +12,13 @@
********************************************************************
function: registry for time, floor, res backends and channel mappings
- last mod: $Id: registry.c,v 1.2 2000/01/22 13:28:29 xiphmont Exp $
+ last mod: $Id: registry.c,v 1.3 2000/03/10 13:21:18 xiphmont Exp $
********************************************************************/
#include "vorbis/codec.h"
#include "registry.h"
+#include "misc.h"
/* seems like major overkill now; the backend numbers will grow into
the infrastructure soon enough */
diff --git a/lib/smallft.c b/lib/smallft.c
index dcbd72c8..c75e451e 100644
--- a/lib/smallft.c
+++ b/lib/smallft.c
@@ -12,7 +12,7 @@
********************************************************************
function: *unnormalized* fft transform
- last mod: $Id: smallft.c,v 1.7 2000/02/09 22:04:16 xiphmont Exp $
+ last mod: $Id: smallft.c,v 1.8 2000/03/10 13:21:18 xiphmont Exp $
********************************************************************/
@@ -33,6 +33,7 @@
#include <string.h>
#include <math.h>
#include "smallft.h"
+#include "misc.h"
static void drfti1(int n, double *wa, int *ifac){
static int ntryh[4] = { 4,2,3,5 };
diff --git a/lib/time0.c b/lib/time0.c
index e0ec1f02..6344a485 100644
--- a/lib/time0.c
+++ b/lib/time0.c
@@ -12,7 +12,7 @@
********************************************************************
function: time backend 0 (dummy)
- last mod: $Id: time0.c,v 1.4 2000/02/23 09:24:32 xiphmont Exp $
+ last mod: $Id: time0.c,v 1.5 2000/03/10 13:21:18 xiphmont Exp $
********************************************************************/
@@ -20,6 +20,7 @@
#include <string.h>
#include "vorbis/codec.h"
#include "registry.h"
+#include "misc.h"
static void pack (vorbis_info_time *i,oggpack_buffer *opb){
}
diff --git a/lib/vorbisfile.c b/lib/vorbisfile.c
index d602902c..d6731c82 100644
--- a/lib/vorbisfile.c
+++ b/lib/vorbisfile.c
@@ -12,7 +12,7 @@
********************************************************************
function: stdio-based convenience library for opening/seeking/decoding
- last mod: $Id: vorbisfile.c,v 1.15 2000/02/23 11:22:47 xiphmont Exp $
+ last mod: $Id: vorbisfile.c,v 1.16 2000/03/10 13:21:18 xiphmont Exp $
********************************************************************/
@@ -23,6 +23,7 @@
#include "vorbis/vorbisfile.h"
#include "os.h"
+#include "misc.h"
/* A 'chained bitstream' is a Vorbis bitstream that contains more than
one logical bitstream arranged end to end (the only form of Ogg
@@ -240,7 +241,6 @@ static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc,
goto bail_header;
}
}
- ogg_stream_clear(&vf->os);
return 0;
bail_header:
@@ -280,15 +280,11 @@ static void _prefetch_all_headers(OggVorbis_File *vf,vorbis_info *first_i,
_seek_helper(vf,vf->offsets[i]);
if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL)==-1){
fprintf(stderr,"Error opening logical bitstream #%d.\n\n",i+1);
-
- ogg_stream_clear(&vf->os); /* clear local storage. This is not
- done in _fetch_headers, as that may
- be called in a non-seekable stream
- (in which case, we need to preserve
- the stream local storage) */
- vf->dataoffsets[i]=-1;
- }else
+ vf->dataoffsets[i]=-1;
+ }else{
vf->dataoffsets[i]=vf->offset;
+ ogg_stream_clear(&vf->os);
+ }
}
/* get the serial number and PCM length of this link. To do this,
@@ -317,6 +313,14 @@ static void _prefetch_all_headers(OggVorbis_File *vf,vorbis_info *first_i,
}
}
+static int _make_decode_ready(OggVorbis_File *vf){
+ if(vf->decode_ready)exit(1);
+ vorbis_synthesis_init(&vf->vd,vf->vi);
+ vorbis_block_init(&vf->vd,&vf->vb);
+ vf->decode_ready=1;
+ return(0);
+}
+
static int _open_seekable(OggVorbis_File *vf){
vorbis_info initial_i;
vorbis_comment initial_c;
@@ -326,8 +330,6 @@ static int _open_seekable(OggVorbis_File *vf){
ogg_page og;
/* is this even vorbis...? */
- vorbis_info_init(&initial_i);
- vorbis_comment_init(&initial_c);
ret=_fetch_headers(vf,&initial_i,&initial_c,&serialno);
dataoffset=vf->offset;
ogg_stream_clear(&vf->os);
@@ -366,10 +368,12 @@ static int _open_nonseekable(OggVorbis_File *vf){
/* we cannot seek. Set up a 'single' (current) logical bitstream entry */
vf->links=1;
vf->vi=malloc(sizeof(vorbis_info));
+ vf->vc=malloc(sizeof(vorbis_info));
/* Try to fetch the headers, maintaining all the storage */
if(_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno)==-1)return(-1);
-
+ _make_decode_ready(vf);
+
return 0;
}
@@ -479,6 +483,10 @@ static int _process_packet(OggVorbis_File *vf,int readp){
leave machine uninitialized */
vf->current_link=link;
+
+ ogg_stream_init(&vf->os,vf->current_serialno);
+ ogg_stream_reset(&vf->os,ogg_page_pageno(&og));
+
}else{
/* we're streaming */
/* fetch the three header packets, build the info struct */
@@ -488,12 +496,7 @@ static int _process_packet(OggVorbis_File *vf,int readp){
link=0;
}
- /* reload */
- ogg_stream_init(&vf->os,vf->current_serialno);
- ogg_stream_reset(&vf->os,ogg_page_pageno(&og));
- vorbis_synthesis_init(&vf->vd,vf->vi+link);
- vorbis_block_init(&vf->vd,&vf->vb);
- vf->decode_ready=1;
+ _make_decode_ready(vf);
}
ogg_stream_pagein(&vf->os,&og);
}
@@ -516,6 +519,7 @@ int ov_clear(OggVorbis_File *vf){
vorbis_comment_clear(vf->vc+i);
}
free(vf->vi);
+ free(vf->vc);
}
if(vf->dataoffsets)free(vf->dataoffsets);
if(vf->pcmlengths)free(vf->pcmlengths);
@@ -525,6 +529,7 @@ int ov_clear(OggVorbis_File *vf){
if(vf->f)fclose(vf->f);
memset(vf,0,sizeof(OggVorbis_File));
}
+ _VDBG_dump();
return(0);
}
@@ -565,11 +570,6 @@ int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
if(ret){
vf->f=NULL;
ov_clear(vf);
- }else{
- ogg_stream_init(&vf->os,vf->current_serialno);
- vorbis_synthesis_init(&vf->vd,vf->vi);
- vorbis_block_init(&vf->vd,&vf->vb);
- vf->decode_ready=1;
}
return(ret);
}
diff --git a/lib/window.c b/lib/window.c
index e2935f00..9ca08d70 100644
--- a/lib/window.c
+++ b/lib/window.c
@@ -12,13 +12,14 @@
********************************************************************
function: window functions
- last mod: $Id: window.c,v 1.6 2000/02/06 13:39:48 xiphmont Exp $
+ last mod: $Id: window.c,v 1.7 2000/03/10 13:21:18 xiphmont Exp $
********************************************************************/
#include <stdlib.h>
#include <math.h>
#include "os.h"
+#include "misc.h"
double *_vorbis_window(int type, int window,int left,int right){
double *ret=calloc(window,sizeof(double));