[Forensics-changes] [yara] 296/415: Use dmalloc to debug heap issues

Hilko Bengen bengen at moszumanska.debian.org
Thu Apr 3 05:43:16 UTC 2014


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

bengen pushed a commit to branch debian
in repository yara.

commit cc4bc5469915629a6499c37ccb515bcf50c5eab0
Author: Victor Manuel Alvarez <vmalvarez at virustotal.com>
Date:   Fri Dec 6 22:36:04 2013 +0100

    Use dmalloc to debug heap issues
---
 configure.ac         |  8 ++++++--
 libyara/configure.ac | 12 ++++++++----
 libyara/mem.c        | 43 ++++++-------------------------------------
 3 files changed, 20 insertions(+), 43 deletions(-)

diff --git a/configure.ac b/configure.ac
index ac83050..d3fc9b6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -16,6 +16,10 @@ AC_CONFIG_HEADERS([config.h])
 AC_CONFIG_FILES([Makefile])
 AC_CONFIG_SUBDIRS([libyara])
 AC_CHECK_LIB(pthread, pthread_create)
-
-AC_SUBST(REVISION)
+AC_ARG_ENABLE([dmalloc],
+  [AS_HELP_STRING([--enable-dmalloc], [enable dmalloc to debug heap-related issues])],
+  [if test x$enableval = xyes; then
+    AC_CHECK_LIB(dmalloc, dmalloc_malloc,, AC_MSG_ERROR(please install dmalloc library))
+    AC_DEFINE([DMALLOC], [], [enable dmalloc])
+  fi])
 AC_OUTPUT
diff --git a/libyara/configure.ac b/libyara/configure.ac
index d8fee1a..a08b022 100644
--- a/libyara/configure.ac
+++ b/libyara/configure.ac
@@ -2,7 +2,7 @@ AC_INIT([libyara], [2.0], [vmalvarez at virustotal.com])
 
 ${CFLAGS=""}
 
-# automake 1.12 seems to require AM_PROG_AR, but automake 1.11 doesn't 
+# automake 1.12 seems to require AM_PROG_AR, but automake 1.11 doesn't
 # recognize it
 
 m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
@@ -15,7 +15,11 @@ AM_PROG_LEX
 AC_PROG_LIBTOOL
 AC_CONFIG_MACRO_DIR([m4])
 AC_CONFIG_HEADERS([config.h])
-AC_CONFIG_FILES([
-			Makefile
-		])
+AC_ARG_ENABLE([dmalloc],
+  [AS_HELP_STRING([--enable-dmalloc], [enable dmalloc to debug heap-related issues])],
+  [if test x$enableval = xyes; then
+    AC_CHECK_LIB(dmalloc, dmalloc_malloc,, AC_MSG_ERROR(please install dmalloc library))
+    AC_DEFINE([DMALLOC], [], [enable dmalloc])
+  fi])
+AC_CONFIG_FILES([Makefile])
 AC_OUTPUT
diff --git a/libyara/mem.c b/libyara/mem.c
index 48a9aa0..bc9b6d6 100644
--- a/libyara/mem.c
+++ b/libyara/mem.c
@@ -64,75 +64,44 @@ char* yr_strdup(const char *s)
 #include <string.h>
 #include <stdio.h>
 
-
-#ifdef DEBUG_HEAP
-static int count;
+#ifdef DMALLOC
+#include <dmalloc.h>
 #endif
 
+
 void yr_heap_alloc()
 {
-  #ifdef DEBUG_HEAP
-  count = 0;
-  #endif
   return;
 }
 
 
 void yr_heap_free()
 {
-  #ifdef DEBUG_HEAP
-  printf("malloc count: %d\n", count);
-  #endif
   return;
 }
 
 
 void* yr_malloc(size_t size)
 {
-  void* result = malloc(size);
-
-  #ifdef DEBUG_HEAP
-  count++;
-  printf("malloc: %p %zd\n", result, size);
-  #endif
-
-  return result;
+  return malloc(size);
 }
 
 
 void* yr_realloc(void* ptr, size_t size)
 {
-  void* result = realloc(ptr, size);
-
-  #ifdef DEBUG_HEAP
-  printf("realloc: %p -> %p\n", ptr, result);
-  #endif
-
-  return result;
+  return realloc(ptr, size);
 }
 
 
 void yr_free(void *ptr)
 {
-  #ifdef DEBUG_HEAP
-  count--;
-  printf("free: %p\n", ptr);
-  #endif
-
   free(ptr);
 }
 
 
 char* yr_strdup(const char *str)
 {
-  void* result = strdup(str);
-
-  #ifdef DEBUG_HEAP
-  count++;
-  printf("strdup: %p %zd %s\n", result, strlen(str) + 1, str);
-  #endif
-
-  return result;
+  return strdup(str);
 }
 
 #endif
\ No newline at end of file

-- 
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