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

conrad at svn.annodex.net conrad at svn.annodex.net
Sat Feb 21 02:53:42 PST 2009


Author: conrad
Date: 2009-02-21 02:53:42 -0800 (Sat, 21 Feb 2009)
New Revision: 3855

Modified:
   liboggz/trunk/src/tools/oggz-chop/cgi.c
   liboggz/trunk/src/tools/oggz-chop/oggz-chop.c
Log:
oggz-chop: chase potential malloc, strdup failures

Modified: liboggz/trunk/src/tools/oggz-chop/cgi.c
===================================================================
--- liboggz/trunk/src/tools/oggz-chop/cgi.c	2009-02-21 07:31:28 UTC (rev 3854)
+++ liboggz/trunk/src/tools/oggz-chop/cgi.c	2009-02-21 10:53:42 UTC (rev 3855)
@@ -103,15 +103,23 @@
 
   if (path_info == NULL) return NULL;
 
-  if (dr == NULL || *dr == '\0') return strdup (path_info);
+  if (dr == NULL || *dr == '\0') {
+    if ((path_translated = strdup (path_info)) == NULL)
+      goto prepend_oom;
+  } else {
+    dr_len = strlen (dr);
 
-  dr_len = strlen (dr);
+    pt_len = dr_len + strlen(path_info) + 1;
+    if ((path_translated = malloc (pt_len)) == NULL)
+      goto prepend_oom;
+    snprintf (path_translated, pt_len , "%s%s", dr, path_info);
+  }
 
-  pt_len = dr_len + strlen(path_info) + 1;
-  path_translated = malloc (pt_len);
-  snprintf (path_translated, pt_len , "%s%s", dr, path_info);
+  return path_translated;
 
-  return path_translated;
+prepend_oom:
+  fprintf (stderr, "oggz-chop: Out of memory");
+  return NULL;
 }
 
 static int

Modified: liboggz/trunk/src/tools/oggz-chop/oggz-chop.c
===================================================================
--- liboggz/trunk/src/tools/oggz-chop/oggz-chop.c	2009-02-21 07:31:28 UTC (rev 3854)
+++ liboggz/trunk/src/tools/oggz-chop/oggz-chop.c	2009-02-21 10:53:42 UTC (rev 3855)
@@ -75,7 +75,8 @@
 {
   OCTrackState * ts;
 
-  ts = (OCTrackState *) malloc (sizeof(*ts));
+  if ((ts = (OCTrackState *) malloc (sizeof(*ts))) == NULL)
+    return NULL;
 
   memset (ts, 0, sizeof(*ts));
 
@@ -103,7 +104,8 @@
 {
   OCTrackState * ts;
 
-  ts = track_state_new ();
+  if ((ts = track_state_new ()) == NULL)
+    return NULL;
 
   if (oggz_table_insert (state, serialno, ts) == ts) {
     return ts;
@@ -146,11 +148,21 @@
 {
   ogg_page * new_og;
 
-  new_og = malloc (sizeof (*og));
-  new_og->header = malloc (og->header_len);
+  if ((new_og = malloc (sizeof (*og))) == NULL)
+    return NULL;
+
+  if ((new_og->header = malloc (og->header_len)) == NULL) {
+    free (new_og);
+    return NULL;
+  }
   new_og->header_len = og->header_len;
   memcpy (new_og->header, og->header, og->header_len);
-  new_og->body = malloc (og->body_len);
+
+  if ((new_og->body = malloc (og->body_len)) == NULL) {
+    free (new_og->header);
+    free (new_og);
+    return NULL;
+  }
   new_og->body_len = og->body_len;
   memcpy (new_og->body, og->body, og->body_len);
 
@@ -201,8 +213,14 @@
 {
   OCPageAccum * pa;
 
-  pa = malloc(sizeof (*pa));
-  pa->og = _ogg_page_copy (og);
+  if ((pa = malloc(sizeof (*pa))) == NULL)
+    return NULL;
+
+  if ((pa->og = _ogg_page_copy (og)) == NULL) {
+    free (pa);
+    return NULL;
+  }
+
   pa->time = time;
 
   return pa;
@@ -359,7 +377,9 @@
     content_type = oggz_stream_get_content (oggz, serialno);
     name = type_names[content_type];
     len = snprintf (NULL, 0, CONTENT_TYPE_FMT, name);
-    ts->fisbone.message_header_fields = malloc(len+1);
+    if ((ts->fisbone.message_header_fields = malloc(len+1)) == NULL) {
+      return -1;
+    }
     snprintf (ts->fisbone.message_header_fields, len+1, CONTENT_TYPE_FMT, name);
     ts->fisbone.current_header_size = len+1;
   }
@@ -717,8 +737,14 @@
         fishead_update (state, og);
       }
     } else {
-      ts = track_state_add (state->tracks, serialno);
-      fisbone_init (oggz, state, ts, serialno);
+      if ((ts = track_state_add (state->tracks, serialno)) == NULL) {
+        /* Out of memory */
+        return OGGZ_STOP_ERR;
+      }
+      if (fisbone_init (oggz, state, ts, serialno) == -1) {
+        /* Out of memory */
+        return OGGZ_STOP_ERR;
+      }
       ts->headers_remaining = ts->fisbone.nr_header_packet;
     }
 



More information about the commits mailing list