X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=lib%2Fmisc.c;h=cf2f1eebb8660fffc1c8522f8631b72a0885bfa8;hb=fdbde9a241d18af61b6561d3cd1faf39f09e49b4;hp=3652d5f373d7793c813e83a9dc4415eb90b35f16;hpb=2e04704e27b5819be1ce094d2a5e2471047d1990;p=platform%2Fupstream%2Flibvorbis.git diff --git a/lib/misc.c b/lib/misc.c index 3652d5f..cf2f1ee 100644 --- a/lib/misc.c +++ b/lib/misc.c @@ -1,42 +1,53 @@ /******************************************************************** * * * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY * - * THE GNU LESSER/LIBRARY PUBLIC LICENSE, WHICH IS INCLUDED WITH * - * THIS SOURCE. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * * * - * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2000 * - * by Monty and the XIPHOPHORUS Company * - * http://www.xiph.org/ * + * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 * + * by the Xiph.Org Foundation http://www.xiph.org/ * * * ********************************************************************/ #define HEAD_ALIGN 32 #include #include +#include #include #include "vorbis/codec.h" #define MISC_C #include "misc.h" +#include static pthread_mutex_t memlock=PTHREAD_MUTEX_INITIALIZER; -void **pointers=NULL; -long *insertlist=NULL; /* We can't embed this in the pointer list; - a pointer can have any value... */ -int ptop=0; -int palloced=0; -int pinsert=0; +static void **pointers=NULL; +static long *insertlist=NULL; /* We can't embed this in the pointer list; + a pointer can have any value... */ + +static char **files=NULL; +static long *file_bytes=NULL; +static int filecount=0; + +static int ptop=0; +static int palloced=0; +static int pinsert=0; typedef struct { char *file; long line; long ptr; + long bytes; } head; -static void *_insert(void *ptr,char *file,long line){ +long global_bytes=0; +long start_time=-1; + +static void *_insert(void *ptr,long bytes,char *file,long line){ ((head *)ptr)->file=file; ((head *)ptr)->line=line; ((head *)ptr)->ptr=pinsert; + ((head *)ptr)->bytes=bytes-HEAD_ALIGN; pthread_mutex_lock(&memlock); if(pinsert>=palloced){ @@ -56,7 +67,56 @@ static void *_insert(void *ptr,char *file,long line){ pinsert=++ptop; else pinsert=insertlist[pinsert]; - + +#ifdef _VDBG_GRAPHFILE + { + FILE *out; + struct timeval tv; + static struct timezone tz; + int i; + char buffer[80]; + gettimeofday(&tv,&tz); + + for(i=0;ifile; + long bytes =((head *)ptr)->bytes; + int i; + + gettimeofday(&tv,&tz); + fprintf(out,"%ld, %ld\n",-start_time+(tv.tv_sec*1000)+(tv.tv_usec/1000), + global_bytes); + fprintf(out,"%ld, %ld\n",-start_time+(tv.tv_sec*1000)+(tv.tv_usec/1000), + global_bytes-((head *)ptr)->bytes); + fclose(out); + + for(i=0;ibytes; + insert=((head *)ptr)->ptr; insertlist[insert]=pinsert; pinsert=insert; + + if(pointers[insert]==NULL){ + fprintf(stderr,"DEBUGGING MALLOC ERROR: freeing previously freed memory\n"); + fprintf(stderr,"\t%s %ld\n",((head *)ptr)->file,((head *)ptr)->line); + } + + if(global_bytes<0){ + fprintf(stderr,"DEBUGGING MALLOC ERROR: freeing unmalloced memory\n"); + } + pointers[insert]=NULL; pthread_mutex_unlock(&memlock); } @@ -78,13 +184,16 @@ void _VDBG_dump(void){ head *ptr=pointers[i]; if(ptr) fprintf(stderr,"unfreed bytes from %s:%ld\n", - ptr->file,ptr->line); + ptr->file,ptr->line); } pthread_mutex_unlock(&memlock); } -extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line){ +void *_VDBG_malloc(void *ptr,long bytes,char *file,long line){ + if(bytes<=0) + fprintf(stderr,"bad malloc request (%ld bytes) from %s:%ld\n",bytes,file,line); + bytes+=HEAD_ALIGN; if(ptr){ ptr-=HEAD_ALIGN; @@ -94,10 +203,10 @@ extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line){ ptr=malloc(bytes); memset(ptr,0,bytes); } - return _insert(ptr,file,line); + return _insert(ptr,bytes,file,line); } -extern void _VDBG_free(void *ptr,char *file,long line){ +void _VDBG_free(void *ptr,char *file,long line){ if(ptr){ ptr-=HEAD_ALIGN; _ripremove(ptr);