[xiph-commits] r3527 - liboggz/trunk/src/tools/oggz-chop

conrad at svn.annodex.net conrad at svn.annodex.net
Thu Mar 27 03:13:57 PDT 2008


Author: conrad
Date: 2008-03-27 03:13:56 -0700 (Thu, 27 Mar 2008)
New Revision: 3527

Modified:
   liboggz/trunk/src/tools/oggz-chop/oggz-chop.c
Log:
oggz-chop: remove memory leaks (add state cleanup routine); tested with
valgrind memcheck+leakcheck


Modified: liboggz/trunk/src/tools/oggz-chop/oggz-chop.c
===================================================================
--- liboggz/trunk/src/tools/oggz-chop/oggz-chop.c	2008-03-26 22:30:39 UTC (rev 3526)
+++ liboggz/trunk/src/tools/oggz-chop/oggz-chop.c	2008-03-27 10:13:56 UTC (rev 3527)
@@ -97,6 +97,25 @@
   }
 }
 
+static void
+state_init (OCState * state)
+{
+  state->tracks = oggz_table_new ();
+  state->written_accum = 0;
+}
+
+static void
+state_clear (OCState * state)
+{
+  int i, ntracks;
+
+  ntracks = oggz_table_size (state->tracks);
+  for (i = 0; i < ntracks; i++) {
+    track_state_delete (oggz_table_nth(state->tracks, i, NULL));
+  }
+  oggz_table_delete (state->tracks);
+}
+
 /************************************************************
  * ogg_page helpers
  */
@@ -137,7 +156,7 @@
 }
 
 static void
-fwrite_ogg_page (FILE * outfile, ogg_page * og)
+fwrite_ogg_page (FILE * outfile, const ogg_page * og)
 {
   if (og == NULL) return;
 
@@ -428,8 +447,7 @@
 {
   OGGZ * oggz;
 
-  state->tracks = oggz_table_new ();
-  state->written_accum = 0;
+  state_init (state);
 
   if (strcmp (state->infilename, "-") == 0) {
     oggz = oggz_open_stdio (stdin, OGGZ_READ|OGGZ_AUTO);
@@ -456,5 +474,7 @@
 
   oggz_close (oggz);
 
+  state_clear (state);
+
   return 0; 
 }



More information about the commits mailing list