[libgsf] Blobs: reduce CRITICALs.



commit 696efd75b31918e50bda954642176beddd5b116b
Author: Morten Welinder <terra gnome org>
Date:   Sat Nov 1 10:52:37 2014 -0400

    Blobs: reduce CRITICALs.
    
    Once we have complained about a file being corrupted, we should not
    produce an avalanche of CRITICALs.

 ChangeLog                 |    6 ++++++
 NEWS                      |    1 +
 gsf/gsf-structured-blob.c |   30 +++++++++++++++++-------------
 3 files changed, 24 insertions(+), 13 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f9b1683..4bb5945 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2014-11-01  Morten Welinder  <terra gnome org>
+
+       * gsf/gsf-structured-blob.c (blob_finalize, blob_dup)
+       (blob_child_by_name, gsf_structured_blob_read): Reduce CRITICALs
+       on corrupted files.
+
 2014-10-28  Morten Welinder  <terra gnome org>
 
        * gsf/gsf-utils.c: Avoid deprecated g_type_init.
diff --git a/NEWS b/NEWS
index 8aa3728..3bebd71 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,7 @@ Allin Cottrell:
 Morten:
        * Plug leak.
        * Dead kittens.
+       * Reduce number of CRITICALs for corrupted files.
 
 --------------------------------------------------------------------------
 libgsf 1.14.30
diff --git a/gsf/gsf-structured-blob.c b/gsf/gsf-structured-blob.c
index 74d76d2..caeadc7 100644
--- a/gsf/gsf-structured-blob.c
+++ b/gsf/gsf-structured-blob.c
@@ -49,8 +49,12 @@ blob_finalize (GObject *obj)
        }
 
        if (blob->children != NULL) {
-               for (i = 0; i < blob->children->len ; i++)
-                       g_object_unref (g_ptr_array_index (blob->children, i));
+               for (i = 0; i < blob->children->len ; i++) {
+                       GsfStructuredBlob *child_blob =
+                               g_ptr_array_index (blob->children, i);
+                       if (child_blob)
+                               g_object_unref (child_blob);
+               }
                g_ptr_array_free (blob->children, TRUE);
                blob->children = NULL;
        }
@@ -75,8 +79,9 @@ blob_dup (GsfInput *input, G_GNUC_UNUSED GError **err)
                g_ptr_array_set_size  (dst->children, src->children->len);
                for (i = 0; i < src->children->len ; i++) {
                        child = g_ptr_array_index (src->children, i);
-                       g_ptr_array_index (dst->children, i) = child;
-                       g_object_ref (child);
+                       g_ptr_array_index (dst->children, i) = child
+                               ? g_object_ref (child)
+                               : NULL;
                }
        }
 
@@ -144,11 +149,10 @@ blob_child_by_name (GsfInfile *infile, char const *name, GError **err)
        GsfStructuredBlob const *blob = (GsfStructuredBlob *) infile;
        if (blob->children != NULL) {
                unsigned i;
-               GsfInput *child;
 
                for (i = 0 ; i < blob->children->len ;) {
-                       child = g_ptr_array_index (blob->children, i);
-                       if (!strcmp (gsf_input_name (child), name))
+                       GsfInput *child = g_ptr_array_index (blob->children, i);
+                       if (child && !strcmp (gsf_input_name (child), name))
                                return gsf_input_dup (child, err);
                }
        }
@@ -227,16 +231,16 @@ gsf_structured_blob_read (GsfInput *input)
        if (GSF_IS_INFILE (input))
                i = gsf_infile_num_children (GSF_INFILE (input));
        if (i > 0) {
-               GsfInput          *child;
-               GsfStructuredBlob *child_blob;
 
                blob->children = g_ptr_array_sized_new (i);
                g_ptr_array_set_size  (blob->children, i);
                while (i-- > 0) {
-                       child = gsf_infile_child_by_index (GSF_INFILE (input), i);
-                       child_blob = gsf_structured_blob_read (child);
-                       g_object_unref (child);
-
+                       GsfInput *child = gsf_infile_child_by_index (GSF_INFILE (input), i);
+                       GsfStructuredBlob *child_blob = NULL;
+                       if (child) {
+                               child_blob = gsf_structured_blob_read (child);
+                               g_object_unref (child);
+                       }
                        g_ptr_array_index (blob->children, i) = child_blob;
 #if 0
                        /*


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]