From f4c12b7fdc0482461f5c52161ea852c9d152cc4e Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Wed, 24 Jan 2018 18:42:12 +0100
Subject: Cleaned the content of loaded binaries.

---
 ChangeLog             |  5 +++++
 src/analysis/binary.c | 56 ++++++++++++++++++++++++---------------------------
 2 files changed, 31 insertions(+), 30 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 58c468f..d80a44d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 18-01-24  Cyrille Bagard <nocbos@gmail.com>
 
+	* src/analysis/binary.c:
+	Clean the content of loaded binaries.
+
+18-01-24  Cyrille Bagard <nocbos@gmail.com>
+
 	* plugins/arm/v7/fetch.c:
 	* plugins/arm/v7/helpers.c:
 	* plugins/arm/v7/operands/coproc.c:
diff --git a/src/analysis/binary.c b/src/analysis/binary.c
index 2769291..f38cf66 100644
--- a/src/analysis/binary.c
+++ b/src/analysis/binary.c
@@ -79,10 +79,7 @@ struct _GLoadedBinary
     DBStorage storages[DBF_COUNT];          /* Lieux d'enregistrement      */
     GList *collections;                     /* Ensemble de modifications   */
 
-    GBinContent *content;                   /* Contenu binaire chargé      */ //// REMME
-
     GExeFormat *format;                     /* Format du binaire           */
-    GDbgFormat *debug;                      /* Informations de débogage    */ //// REMME
     GArchProcessor *proc;                   /* Architecture du binaire     */
 
 
@@ -298,8 +295,6 @@ static void g_loaded_binary_interface_init(GLoadedContentInterface *iface)
 
 static void g_loaded_binary_dispose(GLoadedBinary *binary)
 {
-    g_object_unref(G_OBJECT(binary->content));
-
     if (binary->format != NULL)
         g_object_unref(G_OBJECT(binary->format));
 
@@ -361,8 +356,6 @@ GLoadedBinary *g_loaded_binary_new(GBinContent *content)
     log_variadic_message(LMT_PROCESS, _("Opening binary data from '%s'..."),
                          g_binary_content_describe(content, true));
 
-    result->content = content;
-
     /* Format d'exécutable */
 
     status = find_matching_format(content, NULL, &target);
@@ -448,6 +441,7 @@ GLoadedBinary *g_loaded_binary_new_from_xml(xmlXPathContextPtr context, const ch
     GBinContent *content;                   /* Contenu à référencer        */
     xmlXPathObjectPtr xobject;              /* Cible d'une recherche       */
     unsigned int i;                         /* Boucle de parcours          */
+    bool attached;                          /* Bilan d'un chargement       */
 
     /* Contenus binaires associés */
 
@@ -462,27 +456,21 @@ GLoadedBinary *g_loaded_binary_new_from_xml(xmlXPathContextPtr context, const ch
     free(access);
 
     if (hash == NULL)
-    {
-        free(content_path);
-        return NULL;
-    }
+        goto glbnfx_early_error;
 
     content = g_study_project_find_binary_content_by_hash(project, hash);
+
     free(hash);
 
     if (content == NULL)
-    {
-        free(content_path);
-        return NULL;
-    }
+        goto glbnfx_early_error;
 
     result = g_loaded_binary_new(content);
 
+    g_object_unref(G_OBJECT(content));
+
     if (result == NULL)
-    {
-        free(content_path);
-        return NULL;
-    }
+        goto glbnfx_early_error;
 
     asprintf(&access, "%s/DebugInfo", content_path);
 
@@ -499,25 +487,21 @@ GLoadedBinary *g_loaded_binary_new_from_xml(xmlXPathContextPtr context, const ch
         free(access);
 
         if (hash == NULL)
-        {
-            free(content_path);
             goto glbnfx_error;
-        }
 
         content = g_study_project_find_binary_content_by_hash(project, hash);
+
         free(hash);
 
         if (content == NULL)
-        {
-            free(content_path);
             goto glbnfx_error;
-        }
 
-        if (!g_loaded_binary_attach_debug_info(result, content))
-        {
-            free(content_path);
+        attached = g_loaded_binary_attach_debug_info(result, content);
+
+        g_object_unref(G_OBJECT(content));
+
+        if (!attached)
             goto glbnfx_error;
-        }
 
     }
 
@@ -529,14 +513,26 @@ GLoadedBinary *g_loaded_binary_new_from_xml(xmlXPathContextPtr context, const ch
     /* Elément divers associés au binaire */
 
     if (!g_loaded_binary_load_storage(result, context, path))
-        goto glbnfx_error;
+        goto glbnfx_final_error;
 
     return result;
 
  glbnfx_error:
 
+    free(content_path);
+
+ glbnfx_final_error:
+
+    g_object_unref(G_OBJECT(result));
+
+    return NULL;
+
+ glbnfx_early_error:
+
     g_object_unref(G_OBJECT(result));
 
+    free(content_path);
+
     return NULL;
 
 }
-- 
cgit v0.11.2-87-g4458