[or-cvs] Reorganize some quick-and-dirty code to find out what opens...

Nick Mathewson nickm at seul.org
Mon Oct 3 20:20:41 UTC 2005


Update of /home/or/cvsroot/tor/src/common
In directory moria:/tmp/cvs-serv27221/src/common

Modified Files:
	util.c util.h 
Log Message:
Reorganize some quick-and-dirty code to find out what openssl stuff is leaking, using dmalloc.

Index: util.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/util.c,v
retrieving revision 1.226
retrieving revision 1.227
diff -u -d -r1.226 -r1.227
--- util.c	30 Sep 2005 01:39:24 -0000	1.226
+++ util.c	3 Oct 2005 20:20:38 -0000	1.227
@@ -96,7 +96,7 @@
  * ===== */
 #ifdef USE_DMALLOC
  #include <dmalloc.h>
- #define DMALLOC_FN_ARGS file, line,
+ #define DMALLOC_FN_ARGS , file, line
 #else
  #define dmalloc_strdup(file, line, string, xalloc_b) strdup(string)
 
@@ -116,7 +116,7 @@
  * ignored otherwise.
  */
 void *
-_tor_malloc(DMALLOC_PARAMS size_t size)
+_tor_malloc(size_t size DMALLOC_PARAMS)
 {
   void *result;
 
@@ -141,9 +141,9 @@
  * the process on error.  (Same as calloc(size,1), but never returns NULL.)
  */
 void *
-_tor_malloc_zero(DMALLOC_PARAMS size_t size)
+_tor_malloc_zero(size_t size DMALLOC_PARAMS)
 {
-  void *result = _tor_malloc(DMALLOC_FN_ARGS size);
+  void *result = _tor_malloc(size DMALLOC_FN_ARGS);
   memset(result, 0, size);
   return result;
 }
@@ -153,7 +153,7 @@
  * terminate. (Like realloc(ptr,size), but never returns NULL.)
  */
 void *
-_tor_realloc(DMALLOC_PARAMS void *ptr, size_t size)
+_tor_realloc(void *ptr, size_t size DMALLOC_PARAMS)
 {
   void *result;
 
@@ -170,7 +170,7 @@
  * NULL.)
  */
 char *
-_tor_strdup(DMALLOC_PARAMS const char *s)
+_tor_strdup(const char *s DMALLOC_PARAMS)
 {
   char *dup;
   tor_assert(s);
@@ -190,11 +190,11 @@
  * NULL.)
  */
 char *
-_tor_strndup(DMALLOC_PARAMS const char *s, size_t n)
+_tor_strndup(const char *s, size_t n DMALLOC_PARAMS)
 {
   char *dup;
   tor_assert(s);
-  dup = _tor_malloc(DMALLOC_FN_ARGS n+1);
+  dup = _tor_malloc((n+1) DMALLOC_FN_ARGS);
   /* Performance note: Ordinarily we prefer strlcpy to strncpy.  But
    * this function gets called a whole lot, and platform strncpy is
    * much faster than strlcpy when strlen(s) is much longer than n.

Index: util.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/util.h,v
retrieving revision 1.141
retrieving revision 1.142
diff -u -d -r1.141 -r1.142
--- util.h	30 Sep 2005 01:39:24 -0000	1.141
+++ util.h	3 Oct 2005 20:20:38 -0000	1.142
@@ -48,8 +48,8 @@
 #endif
 
 #ifdef USE_DMALLOC
-#define DMALLOC_PARAMS const char *file, const int line,
-#define DMALLOC_ARGS _SHORT_FILE_, __LINE__,
+#define DMALLOC_PARAMS , const char *file, const int line
+#define DMALLOC_ARGS , _SHORT_FILE_, __LINE__
 #else
 #define DMALLOC_PARAMS
 #define DMALLOC_ARGS
@@ -61,11 +61,11 @@
 #define tor_fragile_assert()
 
 /* Memory management */
-void *_tor_malloc(DMALLOC_PARAMS size_t size);
-void *_tor_malloc_zero(DMALLOC_PARAMS size_t size);
-void *_tor_realloc(DMALLOC_PARAMS void *ptr, size_t size);
-char *_tor_strdup(DMALLOC_PARAMS const char *s);
-char *_tor_strndup(DMALLOC_PARAMS const char *s, size_t n);
+void *_tor_malloc(size_t size DMALLOC_PARAMS);
+void *_tor_malloc_zero(size_t size DMALLOC_PARAMS);
+void *_tor_realloc(void *ptr, size_t size DMALLOC_PARAMS);
+char *_tor_strdup(const char *s DMALLOC_PARAMS);
+char *_tor_strndup(const char *s, size_t n DMALLOC_PARAMS);
 #ifdef USE_DMALLOC
 extern int dmalloc_free(const char *file, const int line, void *pnt,
                         const int func_id);
@@ -79,11 +79,11 @@
 #define tor_free(p) do { if (p) {free(p); (p)=NULL;} } while (0)
 #endif
 
-#define tor_malloc(size)       _tor_malloc(DMALLOC_ARGS size)
-#define tor_malloc_zero(size)  _tor_malloc_zero(DMALLOC_ARGS size)
-#define tor_realloc(ptr, size) _tor_realloc(DMALLOC_ARGS ptr, size)
-#define tor_strdup(s)          _tor_strdup(DMALLOC_ARGS s)
-#define tor_strndup(s, n)      _tor_strndup(DMALLOC_ARGS s, n)
+#define tor_malloc(size)       _tor_malloc(size DMALLOC_ARGS)
+#define tor_malloc_zero(size)  _tor_malloc_zero(size DMALLOC_ARGS)
+#define tor_realloc(ptr, size) _tor_realloc(ptr, size DMALLOC_ARGS)
+#define tor_strdup(s)          _tor_strdup(s DMALLOC_ARGS)
+#define tor_strndup(s, n)      _tor_strndup(s, n DMALLOC_ARGS)
 
 /* String manipulation */
 #define HEX_CHARACTERS "0123456789ABCDEFabcdef"



More information about the tor-commits mailing list