[or-cvs] r17157: {tor} This patch changes some of the code in util.c to refactor ca (tor/trunk/src/common)

ioerror at seul.org ioerror at seul.org
Sun Oct 26 22:56:54 UTC 2008


Author: ioerror
Date: 2008-10-26 18:56:53 -0400 (Sun, 26 Oct 2008)
New Revision: 17157

Modified:
   tor/trunk/src/common/util.c
Log:
This patch changes some of the code in util.c to refactor calls to
dmalloc_malloc, dmalloc_realloc and dmalloc_strdup. It only calls those
functions if we're using the magic USE_DMALLOC macro. If we're not doing
that, we call the normal malloc, realloc and strdup. This is my first
night at malloc disambiguation club, so I had to disambiguate. Also, first commit, I have my commit bit now. Huzzzah!!!


Modified: tor/trunk/src/common/util.c
===================================================================
--- tor/trunk/src/common/util.c	2008-10-26 22:14:22 UTC (rev 17156)
+++ tor/trunk/src/common/util.c	2008-10-26 22:56:53 UTC (rev 17157)
@@ -95,14 +95,8 @@
  #endif
 
 #else /* not using dmalloc */
- #define dmalloc_strdup(file, line, string, xalloc_b) strdup(string)
-
- #define dmalloc_malloc(file, line, size, func_id, alignment, xalloc_b) \
-     malloc(size)
  #define DMALLOC_FUNC_MALLOC 0
 
- #define dmalloc_realloc(file, line, old_pnt, new_size, func_id, xalloc_b) \
-     realloc((old_pnt), (new_size))
  #define DMALLOC_FUNC_REALLOC 0
  #define DMALLOC_FN_ARGS
 #endif
@@ -125,7 +119,12 @@
     size=1;
   }
 #endif
+
+#ifdef USE_DMALLOC
   result = dmalloc_malloc(file, line, size, DMALLOC_FUNC_MALLOC, 0, 0);
+#else
+  result = malloc(size);
+#endif
 
   if (PREDICT_UNLIKELY(result == NULL)) {
     log_err(LD_MM,"Out of memory on malloc(). Dying.");
@@ -158,7 +157,12 @@
 {
   void *result;
 
+#ifdef USE_DMALLOC
   result = dmalloc_realloc(file, line, ptr, size, DMALLOC_FUNC_REALLOC, 0);
+#else
+  result = realloc(ptr, size);
+#endif
+
   if (PREDICT_UNLIKELY(result == NULL)) {
     log_err(LD_MM,"Out of memory on realloc(). Dying.");
     exit(1);
@@ -176,7 +180,11 @@
   char *dup;
   tor_assert(s);
 
+#ifdef USE_DMALLOC
   dup = dmalloc_strdup(file, line, s, 0);
+#else 
+  dup = strdup(s);
+#endif
   if (PREDICT_UNLIKELY(dup == NULL)) {
     log_err(LD_MM,"Out of memory on strdup(). Dying.");
     exit(1);



More information about the tor-commits mailing list