[Forensics-changes] [yara] 324/368: Fix memory leaks
Hilko Bengen
bengen at moszumanska.debian.org
Sat Jul 1 10:30:53 UTC 2017
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to annotated tag v3.5.0
in repository yara.
commit 89cafe616760389deedf9dfa8cf95ce7da052e13
Author: plusvic <plusvic at gmail.com>
Date: Wed Jun 15 16:09:57 2016 +0200
Fix memory leaks
---
libyara/atoms.c | 5 +++++
libyara/object.c | 29 +++++++++++++++++++----------
2 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/libyara/atoms.c b/libyara/atoms.c
index bbe98cc..cb96797 100644
--- a/libyara/atoms.c
+++ b/libyara/atoms.c
@@ -1067,6 +1067,7 @@ int yr_atoms_extract_from_re(
yr_atoms_extract_triplets(re->root_node, &triplet_atoms),
{
yr_atoms_list_destroy(*atoms);
+ yr_atoms_list_destroy(triplet_atoms);
*atoms = NULL;
});
@@ -1087,6 +1088,7 @@ int yr_atoms_extract_from_re(
_yr_atoms_wide(*atoms, &wide_atoms),
{
yr_atoms_list_destroy(*atoms);
+ yr_atoms_list_destroy(wide_atoms);
*atoms = NULL;
});
@@ -1107,6 +1109,7 @@ int yr_atoms_extract_from_re(
_yr_atoms_case_insentive(*atoms, &case_insentive_atoms),
{
yr_atoms_list_destroy(*atoms);
+ yr_atoms_list_destroy(case_insentive_atoms);
*atoms = NULL;
});
@@ -1194,6 +1197,7 @@ int yr_atoms_extract_from_string(
_yr_atoms_wide(*atoms, &wide_atoms),
{
yr_atoms_list_destroy(*atoms);
+ yr_atoms_list_destroy(wide_atoms);
*atoms = NULL;
});
@@ -1214,6 +1218,7 @@ int yr_atoms_extract_from_string(
_yr_atoms_case_insentive(*atoms, &case_insentive_atoms),
{
yr_atoms_list_destroy(*atoms);
+ yr_atoms_list_destroy(case_insentive_atoms);
*atoms = NULL;
});
diff --git a/libyara/object.c b/libyara/object.c
index ae1e31f..c8348f6 100644
--- a/libyara/object.c
+++ b/libyara/object.c
@@ -153,6 +153,10 @@ int yr_object_create(
case OBJECT_TYPE_DICTIONARY:
((YR_OBJECT_DICTIONARY*) parent)->prototype_item = obj;
break;
+
+ case OBJECT_TYPE_FUNCTION:
+ ((YR_OBJECT_FUNCTION*) parent)->return_obj = obj;
+ break;
}
}
@@ -195,34 +199,39 @@ int yr_object_function_create(
if (parent != NULL)
{
+ // The parent of a function must be a structure.
+
assert(parent->type == OBJECT_TYPE_STRUCTURE);
// Try to find if the structure already has a function
- // with that name. In that case this is a function oveload.
+ // with that name. In that case this is a function overload.
f = (YR_OBJECT_FUNCTION*) yr_object_lookup_field(parent, identifier);
+ // Overloaded functions must have the same return type.
+
if (f != NULL && return_type != f->return_obj->type)
return ERROR_WRONG_RETURN_TYPE;
}
if (f == NULL) // Function doesn't exist yet
{
- // Let's create the result object first
-
- FAIL_ON_ERROR(yr_object_create(return_type, "result", NULL, &return_obj));
-
- FAIL_ON_ERROR_WITH_CLEANUP(
+ FAIL_ON_ERROR(
yr_object_create(
OBJECT_TYPE_FUNCTION,
identifier,
parent,
- &o),
- yr_object_destroy(return_obj));
+ &o));
+
+ FAIL_ON_ERROR_WITH_CLEANUP(
+ yr_object_create(
+ return_type,
+ "result",
+ o,
+ &return_obj),
+ yr_object_destroy(o));
f = (YR_OBJECT_FUNCTION*) o;
- f->return_obj = return_obj;
- f->return_obj->parent = (YR_OBJECT*) f;
}
for (i = 0; i < MAX_OVERLOADED_FUNCTIONS; i++)
--
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