1 /********************************************************************
3 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
5 * THE GNU LESSER/LIBRARY PUBLIC LICENSE, WHICH IS INCLUDED WITH *
6 * THIS SOURCE. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
8 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2000 *
9 * by Monty <monty@xiph.org> and the XIPHOPHORUS Company *
10 * http://www.xiph.org/ *
12 ********************************************************************/
18 #include "vorbis/codec.h"
22 static pthread_mutex_t memlock=PTHREAD_MUTEX_INITIALIZER;
24 long *insertlist=NULL; /* We can't embed this in the pointer list;
25 a pointer can have any value... */
36 static void *_insert(void *ptr,char *file,long line){
37 ((head *)ptr)->file=file;
38 ((head *)ptr)->line=line;
39 ((head *)ptr)->ptr=pinsert;
41 pthread_mutex_lock(&memlock);
42 if(pinsert>=palloced){
45 pointers=(void **)_ogg_realloc(pointers,sizeof(void **)*palloced);
46 insertlist=(long *)_ogg_realloc(insertlist,sizeof(long *)*palloced);
48 pointers=(void **)_ogg_malloc(sizeof(void **)*palloced);
49 insertlist=(long *)_ogg_malloc(sizeof(long *)*palloced);
53 pointers[pinsert]=ptr;
58 pinsert=insertlist[pinsert];
60 pthread_mutex_unlock(&memlock);
61 return(ptr+HEAD_ALIGN);
64 static void _ripremove(void *ptr){
66 pthread_mutex_lock(&memlock);
67 insert=((head *)ptr)->ptr;
68 insertlist[insert]=pinsert;
70 pointers[insert]=NULL;
71 pthread_mutex_unlock(&memlock);
74 void _VDBG_dump(void){
76 pthread_mutex_lock(&memlock);
78 head *ptr=pointers[i];
80 fprintf(stderr,"unfreed bytes from %s:%ld\n",
84 pthread_mutex_unlock(&memlock);
87 extern void *_VDBG__ogg_malloc(void *ptr,long bytes,char *file,long line){
92 ptr=_ogg_realloc(ptr,bytes);
94 ptr=_ogg_malloc(bytes);
97 return _insert(ptr,file,line);
100 extern void _VDBG_free(void *ptr,char *file,long line){