[xiph-cvs] cvs commit: vorbis-tools/vorbiscomment vcedit.c vcedit.h

Michael Smith msmith at xiph.org
Tue Jul 9 05:20:44 PDT 2002



msmith      02/07/09 05:20:44

  Modified:    vorbiscomment vcedit.c vcedit.h
  Log:
  Plug enormous gaping memory leaks.

Revision  Changes    Path
1.19      +16 -15    vorbis-tools/vorbiscomment/vcedit.c

Index: vcedit.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/vorbiscomment/vcedit.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- vcedit.c	2002/03/30 14:40:59	1.18
+++ vcedit.c	2002/07/09 12:20:43	1.19
@@ -6,7 +6,7 @@
  *
  * Comment editing backend, suitable for use by nice frontend interfaces.
  *
- * last modified: $Id: vcedit.c,v 1.18 2002/03/30 14:40:59 msmith Exp $
+ * last modified: $Id: vcedit.c,v 1.19 2002/07/09 12:20:43 msmith Exp $
  */
 
 #include <stdio.h>
@@ -45,25 +45,29 @@
         {
                 vorbis_comment_clear(state->vc);
                 free(state->vc);
-		state->vc=NULL;
         }
         if(state->os)
         {
                 ogg_stream_clear(state->os);
                 free(state->os);
-		state->os=NULL;
         }
         if(state->oy)
         {
                 ogg_sync_clear(state->oy);
                 free(state->oy);
-		state->oy=NULL;
         }
         if(state->vendor)
-	{
                 free(state->vendor);
-		state->vendor=NULL;
-	}
+    if(state->mainbuf)
+        free(state->mainbuf);
+    if(state->bookbuf)
+        free(state->bookbuf);
+    if(state->vi) {
+       	vorbis_info_clear(state->vi);
+        free(state->vi);
+    }
+
+    memset(state, 0, sizeof(*state));
 }
 
 void vcedit_clear(vcedit_state *state)
@@ -130,7 +134,7 @@
 
 static int _blocksize(vcedit_state *s, ogg_packet *p)
 {
-	int this = vorbis_packet_blocksize(&s->vi, p);
+	int this = vorbis_packet_blocksize(s->vi, p);
         int ret = (this + s->prevW)/4;
 
         if(!s->prevW)
@@ -223,7 +227,8 @@
         state->os = malloc(sizeof(ogg_stream_state));
         ogg_stream_init(state->os, state->serial);
 
-	vorbis_info_init(&state->vi);
+    state->vi = malloc(sizeof(vorbis_info));
+	vorbis_info_init(state->vi);
 
         state->vc = malloc(sizeof(vorbis_comment));
         vorbis_comment_init(state->vc);
@@ -240,7 +245,7 @@
                 goto err;
         }
 
-	if(vorbis_synthesis_headerin(&state->vi, state->vc, &header_main) < 0)
+	if(vorbis_synthesis_headerin(state->vi, state->vc, &header_main) < 0)
         {
                 state->lasterror = _("Ogg bitstream does not contain vorbis data.");
                 goto err;
@@ -268,7 +273,7 @@
                                                 state->lasterror = _("Corrupt secondary header.");
                                                 goto err;
                                         }
-					vorbis_synthesis_headerin(&state->vi, state->vc, header);
+					vorbis_synthesis_headerin(state->vi, state->vc, header);
                                         if(i==1)
                                         {
                                                 state->booklen = header->bytes;
@@ -417,10 +422,6 @@
                                         out) != (size_t) ogout.body_len)
                         goto cleanup;
         }
-
-	/* FIXME: freeing this here probably leaks memory */
-	/* Done with this, now */
-	vorbis_info_clear(&state->vi);
 
         if (state->extrapage)
         {

<p><p>1.10      +1 -1      vorbis-tools/vorbiscomment/vcedit.h

Index: vcedit.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/vorbiscomment/vcedit.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- vcedit.h	2001/11/07 12:45:03	1.9
+++ vcedit.h	2002/07/09 12:20:43	1.10
@@ -27,7 +27,7 @@
         ogg_stream_state	*os;
 
         vorbis_comment		*vc;
-	vorbis_info          vi;
+	vorbis_info         *vi;
 
         vcedit_read_func read;
         vcedit_write_func write;

<p><p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list