[xiph-commits] r3818 - liboggz/trunk/src/tools

conrad at svn.annodex.net conrad at svn.annodex.net
Sun Dec 7 15:57:15 PST 2008


Author: conrad
Date: 2008-12-07 15:57:14 -0800 (Sun, 07 Dec 2008)
New Revision: 3818

Modified:
   liboggz/trunk/src/tools/oggz-dump.c
Log:
oggz-dump: handle out-of-memory errors


Modified: liboggz/trunk/src/tools/oggz-dump.c
===================================================================
--- liboggz/trunk/src/tools/oggz-dump.c	2008-12-07 12:35:17 UTC (rev 3817)
+++ liboggz/trunk/src/tools/oggz-dump.c	2008-12-07 23:57:14 UTC (rev 3818)
@@ -109,14 +109,34 @@
   printf ("Please report bugs to <ogg-dev at xiph.org>\n");
 }
 
+static void
+exit_out_of_memory (void)
+{
+  fprintf (stderr, "%s: Out of memory\n", progname);
+  exit (1);
+}
+
 static ODData *
 oddata_new ()
 {
   ODData * oddata = malloc (sizeof (ODData));
+
+  if (oddata == NULL) return NULL;
+
   memset (oddata, 0, sizeof (ODData));
 
   oddata->serialno_table = oggz_table_new ();
+  if (oddata->serialno_table == NULL) {
+    free (oddata);
+    return NULL;
+  }
+
   oddata->content_types_table = oggz_table_new ();
+  if (oddata->content_types_table == NULL) {
+    free (oddata->serialno_table);
+    free (oddata);
+    return NULL;
+  }
 
   oddata->dump_bits = 0;
   oddata->dump_char = 1;
@@ -383,6 +403,8 @@
   }
 
   oggz = oggz_new (OGGZ_WRITE|OGGZ_NONSTRICT|OGGZ_AUTO);
+  if (oggz == NULL)
+    exit_out_of_memory();
 
   while (fgets (line, 120, infile)) {
     line_offset = 0;
@@ -457,13 +479,9 @@
 	      new_size = max_bytes * 2;
 	    }
 
-	    new_packet =
-	      (unsigned char *) realloc ((void *)packet, new_size);
+	    new_packet = (unsigned char *) realloc((void *)packet, new_size);
 	    if (new_packet == NULL) {
-	      fprintf (stderr,
-		       "%s: error allocating memory for packet data\n",
-		       progname);
-	      exit (1);
+              exit_out_of_memory ();
 	    } else {
 	      max_bytes = (long)new_size;
 	      packet = new_packet;
@@ -546,6 +564,8 @@
   }
 
   oddata = oddata_new ();
+  if (oddata == NULL)
+    exit_out_of_memory();
 
   oddata->read_packet = read_packet;
 



More information about the commits mailing list