[Forensics-changes] [yara] 220/407: Fix memory and handle leaks

Hilko Bengen bengen at moszumanska.debian.org
Sat Jul 1 10:28:28 UTC 2017


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag v3.3.0
in repository yara.

commit 8e555903be01340af62d14e89fb7773541e69e89
Author: Victor M. Alvarez <plusvic at gmail.com>
Date:   Fri Nov 21 09:44:44 2014 +0100

    Fix memory and handle leaks
---
 yara.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/yara.c b/yara.c
index 51f04f6..4c3cba2 100644
--- a/yara.c
+++ b/yara.c
@@ -115,8 +115,7 @@ typedef struct _EXTERNAL
 typedef struct _MODULE_DATA
 {
   const char* module_name;
-  void* module_data;
-  size_t module_data_size;
+  YR_MAPPED_FILE mapped_file;
   struct _MODULE_DATA* next;
 
 } MODULE_DATA;
@@ -593,8 +592,8 @@ int callback(int message, void* message_data, void* user_data)
       {
         if (strcmp(module_data->module_name, mi->module_name) == 0)
         {
-          mi->module_data = module_data->module_data;
-          mi->module_data_size = module_data->module_data_size;
+          mi->module_data = module_data->mapped_file.data;
+          mi->module_data_size = module_data->mapped_file.size;
           break;
         }
 
@@ -690,7 +689,12 @@ void cleanup()
   while(module_data != NULL)
   {
     next_module_data = module_data->next;
-    free(module_data);
+
+    yr_filemap_unmap(&module_data->mapped_file);
+
+    free((void*) module_data->module_name);
+    free((void*) module_data);
+
     module_data = next_module_data;
   }
 
@@ -723,8 +727,6 @@ int process_cmd_line(
   EXTERNAL* external;
   MODULE_DATA* module_data;
 
-  YR_MAPPED_FILE mapped_file;
-
   opterr = 0;
 
   while ((c = getopt (argc, (char**) argv, "wrnsvgma:l:t:i:d:x:p:f")) != -1)
@@ -848,8 +850,14 @@ int process_cmd_line(
 
         module_data = (MODULE_DATA*) malloc(sizeof(MODULE_DATA));
 
-        if (module_data == NULL)
+        if (module_data != NULL)
+          module_data->module_name = strdup(optarg);
+
+        if (module_data == NULL || module_data->module_name == NULL)
         {
+          if (module_data != NULL)
+            free(module_data);
+
           fprintf(stderr, "Not enough memory.\n");
           return 0;
         }
@@ -857,16 +865,13 @@ int process_cmd_line(
         *equal_sign = '\0';
         value = equal_sign + 1;
 
-        if (yr_filemap_map(value, &mapped_file) != ERROR_SUCCESS)
+        if (yr_filemap_map(value, &module_data->mapped_file) != ERROR_SUCCESS)
         {
           free(module_data);
           fprintf(stderr, "Could not open file \"%s\".\n", value);
           return 0;
         }
 
-        module_data->module_name = strdup(optarg);
-        module_data->module_data = mapped_file.data;
-        module_data->module_data_size = mapped_file.size;
         module_data->next = modules_data_list;
         modules_data_list = module_data;
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/forensics/yara.git



More information about the forensics-changes mailing list