[Forensics-changes] [yara] 184/192: Fix memory leak.
Hilko Bengen
bengen at moszumanska.debian.org
Sat Jul 1 10:32:03 UTC 2017
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to annotated tag v3.6.0
in repository yara.
commit 0e85b50552bec0492bd1434b5f80ec0ee2d31d58
Author: plusvic <plusvic at gmail.com>
Date: Tue May 16 16:53:14 2017 +0200
Fix memory leak.
Function yr_re_exec was returning with error after RE_MAX_FIBERS was reached, but the currently running fibers weren’t put back into the fiber pool, causing a memory leak. Additionally, if yr_re_exec was called again by the same thread it returned immediately with ERROR_TOO_MANY_RE_FIBERS, as no ready-to run thread was found in the pool.
---
libyara/re.c | 48 ++++++++++++++++++++++++++++++------------------
1 file changed, 30 insertions(+), 18 deletions(-)
diff --git a/libyara/re.c b/libyara/re.c
index 5c55382..f9f5cf3 100644
--- a/libyara/re.c
+++ b/libyara/re.c
@@ -1581,7 +1581,7 @@ void _yr_re_fiber_kill_tail(
//
-// _yr_re_fiber_kill_tail
+// _yr_re_fiber_kill_all
//
// Kills all fibers in the fiber list.
//
@@ -1939,7 +1939,9 @@ int yr_re_exec(
fibers.head = fiber;
fibers.tail = fiber;
- FAIL_ON_ERROR(_yr_re_fiber_sync(&fibers, &storage->fiber_pool, fiber));
+ FAIL_ON_ERROR_WITH_CLEANUP(
+ _yr_re_fiber_sync(&fibers, &storage->fiber_pool, fiber),
+ _yr_re_fiber_kill_all(&fibers, &storage->fiber_pool));
while (fibers.head != NULL)
{
@@ -2116,19 +2118,23 @@ int yr_re_exec(
{
if (flags & RE_FLAGS_BACKWARDS)
{
- FAIL_ON_ERROR(callback(
- input + character_size,
- bytes_matched,
- flags,
- callback_args));
+ FAIL_ON_ERROR_WITH_CLEANUP(
+ callback(
+ input + character_size,
+ bytes_matched,
+ flags,
+ callback_args),
+ _yr_re_fiber_kill_all(&fibers, &storage->fiber_pool));
}
else
{
- FAIL_ON_ERROR(callback(
- input_data,
- bytes_matched,
- flags,
- callback_args));
+ FAIL_ON_ERROR_WITH_CLEANUP(
+ callback(
+ input_data,
+ bytes_matched,
+ flags,
+ callback_args),
+ _yr_re_fiber_kill_all(&fibers, &storage->fiber_pool));
}
}
@@ -2157,14 +2163,16 @@ int yr_re_exec(
break;
case ACTION_CONTINUE:
- FAIL_ON_ERROR(
- _yr_re_fiber_sync(&fibers, &storage->fiber_pool, fiber))
+ FAIL_ON_ERROR_WITH_CLEANUP(
+ _yr_re_fiber_sync(&fibers, &storage->fiber_pool, fiber),
+ _yr_re_fiber_kill_all(&fibers, &storage->fiber_pool));
break;
default:
next_fiber = fiber->next;
- FAIL_ON_ERROR(
- _yr_re_fiber_sync(&fibers, &storage->fiber_pool, fiber));
+ FAIL_ON_ERROR_WITH_CLEANUP(
+ _yr_re_fiber_sync(&fibers, &storage->fiber_pool, fiber),
+ _yr_re_fiber_kill_all(&fibers, &storage->fiber_pool));
fiber = next_fiber;
}
}
@@ -2174,12 +2182,16 @@ int yr_re_exec(
if (flags & RE_FLAGS_SCAN && bytes_matched < max_bytes_matched)
{
- FAIL_ON_ERROR(_yr_re_fiber_create(&storage->fiber_pool, &fiber));
+ FAIL_ON_ERROR_WITH_CLEANUP(
+ _yr_re_fiber_create(&storage->fiber_pool, &fiber),
+ _yr_re_fiber_kill_all(&fibers, &storage->fiber_pool));
fiber->ip = re_code;
_yr_re_fiber_append(&fibers, fiber);
- FAIL_ON_ERROR(_yr_re_fiber_sync(&fibers, &storage->fiber_pool, fiber));
+ FAIL_ON_ERROR_WITH_CLEANUP(
+ _yr_re_fiber_sync(&fibers, &storage->fiber_pool, fiber),
+ _yr_re_fiber_kill_all(&fibers, &storage->fiber_pool));
}
}
--
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