Commit 5f3ff711 authored by conrad's avatar conrad
Browse files

oggz-comment: handle out-of-memory


git-svn-id: http://svn.annodex.net/liboggz/trunk@3819 8158c8cd-e7e1-0310-9fa4-c5954c97daef
parent 40c7cff9
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h> /* , ja */
#include <errno.h> #include <errno.h>
#include <getopt.h> #include <getopt.h>
...@@ -98,23 +97,41 @@ static OCData * ...@@ -98,23 +97,41 @@ static OCData *
ocdata_new () ocdata_new ()
{ {
OCData *ocdata = malloc (sizeof (OCData)); OCData *ocdata = malloc (sizeof (OCData));
assert (ocdata != NULL);
if (ocdata == NULL) return NULL;
memset (ocdata, 0, sizeof (OCData)); memset (ocdata, 0, sizeof (OCData));
ocdata->do_all = 1; ocdata->do_all = 1;
ocdata->storer = oggz_new (OGGZ_WRITE); ocdata->storer = oggz_new (OGGZ_WRITE);
if (ocdata->storer == NULL)
goto err_storer;
ocdata->seen_tracks = oggz_table_new (); ocdata->seen_tracks = oggz_table_new ();
assert (ocdata->seen_tracks != NULL); if (ocdata->seen_tracks == NULL)
goto err_seen_tracks;
ocdata->serialno_table = oggz_table_new(); ocdata->serialno_table = oggz_table_new();
assert (ocdata->serialno_table != NULL); if (ocdata->serialno_table == NULL)
goto err_serialno_table;
ocdata->content_types_table = oggz_table_new(); ocdata->content_types_table = oggz_table_new();
assert (ocdata->content_types_table != NULL); if (ocdata->content_types_table == NULL)
goto err_content_types_table;
return ocdata; return ocdata;
err_content_types_table:
free (ocdata->serialno_table);
err_serialno_table:
free (ocdata->seen_tracks);
err_seen_tracks:
free (ocdata->storer);
err_storer:
free (ocdata);
return NULL;
} }
static void static void
...@@ -312,7 +329,7 @@ edit_comments (OCData * ocdata, char * outfilename) ...@@ -312,7 +329,7 @@ edit_comments (OCData * ocdata, char * outfilename)
/* Set up writer, filling in ocdata for callbacks */ /* Set up writer, filling in ocdata for callbacks */
if ((ocdata->writer = oggz_new (OGGZ_WRITE)) == NULL) { if ((ocdata->writer = oggz_new (OGGZ_WRITE)) == NULL) {
printf ("Unable to create new writer\n"); fprintf (stderr, "Unable to create new writer: out of memory\n");
} }
/* Set a page reader to process bos pages */ /* Set a page reader to process bos pages */
...@@ -454,6 +471,10 @@ main (int argc, char ** argv) ...@@ -454,6 +471,10 @@ main (int argc, char ** argv)
} }
ocdata = ocdata_new (); ocdata = ocdata_new ();
if (ocdata == NULL) {
fprintf (stderr, "oggz-comment: out of memory\n");
exit (1);
}
while (1) { while (1) {
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment