]> granicus.if.org Git - curl/commitdiff
MemoryTracking: fix logging of free() calls done where Curl_safefree is called
authorYang Tse <yangsita@gmail.com>
Fri, 2 Sep 2011 17:40:53 +0000 (19:40 +0200)
committerYang Tse <yangsita@gmail.com>
Fri, 2 Sep 2011 17:40:53 +0000 (19:40 +0200)
Just internal stuff...

Curl_safefree is now a macro defined in memdebug.h instead of a function
prototyped in url.h and implemented in url.c, so inclusion of url.h is no
longer required in order to simply use Curl_safefree.

Provide definition of macro WHILE_FALSE in setup_once.h in order to allow
other macros such as DEBUGF and DEBUGASSERT, and code using it, to compile
without 'conditional expression is constant' warnings.

The WHILE_FALSE stuff fixes 150+ MSVC compiler warnings.

lib/memdebug.h
lib/mprintf.c
lib/multi.c
lib/select.c
lib/setup_once.h
lib/transfer.c
lib/url.c
lib/url.h

index 02df088777be76b0cbddad455586988806d752d8..a042bb474459626383bed30df6658079716036de 100644 (file)
@@ -1,6 +1,6 @@
-#ifdef CURLDEBUG
 #ifndef HEADER_CURL_MEMDEBUG_H
 #define HEADER_CURL_MEMDEBUG_H
+#ifdef CURLDEBUG
 /***************************************************************************
  *                                  _   _ ____  _
  *  Project                     ___| | | |  _ \| |
@@ -139,9 +139,21 @@ CURL_EXTERN int curl_fclose(FILE *file, int line, const char *source);
 
 #endif /* MEMDEBUG_NODEFINES */
 
-#endif /* HEADER_CURL_MEMDEBUG_H */
 #endif /* CURLDEBUG */
 
+/*
+** Following section applies even when CURLDEBUG is not defined.
+*/
+
 #ifndef fake_sclose
-#define fake_sclose(x)
+#define fake_sclose(x)  do { } WHILE_FALSE
 #endif
+
+/*
+ * Curl_safefree defined as a macro to allow MemoryTracking feature
+ * to log free() calls at same location where Curl_safefree is used.
+ */
+
+#define Curl_safefree(ptr)  do {if((ptr)) free((ptr));} WHILE_FALSE
+
+#endif /* HEADER_CURL_MEMDEBUG_H */
index 38732e099e884d646a2c6c7d181e7cf77915a6e8..0990f4024b782cd436a929c8ca92c1e437942b1a 100644 (file)
@@ -103,7 +103,7 @@ static const char upper_digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
       done++; \
     else \
      return done; /* return immediately on failure */ \
-  } while(0)
+  } WHILE_FALSE
 
 /* Data type to read from the arglist */
 typedef enum  {
index aee190ceaada0a877d06dd85e0e0e22f904fa772..d100ef0a02cfc853ec614324ff2d8719232fe9e0 100644 (file)
@@ -952,8 +952,8 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
   data = easy->easy_handle;
 
   do {
-    /* this is a do-while loop just to allow a break to skip to the end
-       of it */
+    /* this is a single-iteration do-while loop just to allow a
+       break to skip to the end of it */
     bool disconnect_conn = FALSE;
 
     /* Handle the case when the pipe breaks, i.e., the connection
@@ -1657,7 +1657,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
       else if(easy->easy_conn && Curl_pgrsUpdate(easy->easy_conn))
         easy->result = CURLE_ABORTED_BY_CALLBACK;
     }
-  } while(0);
+  } WHILE_FALSE; /* just to break out from! */
 
   if(CURLM_STATE_COMPLETED == easy->state) {
     if(data->dns.hostcachetype == HCACHE_MULTI) {
index 56dbc44f4e52f827ebfa395f885de86b5600bace..bd5fa075dc0d38b9a792a5f68f27ebf9adeabd94 100644 (file)
@@ -49,7 +49,7 @@
 /* Winsock and TPF sockets are not in range [0..FD_SETSIZE-1] */
 
 #if defined(USE_WINSOCK) || defined(TPF)
-#define VERIFY_SOCK(x) do { } while(0)
+#define VERIFY_SOCK(x) do { } WHILE_FALSE
 #else
 #define VALID_SOCK(s) (((s) >= 0) && ((s) < FD_SETSIZE))
 #define VERIFY_SOCK(x) do { \
@@ -57,7 +57,7 @@
     SET_SOCKERRNO(EINVAL); \
     return -1; \
   } \
-} while(0)
+} WHILE_FALSE
 #endif
 
 /* Convenience local macros */
index 4f7d0d79144547afe47e6223f42eabb104ed7fd1..63a3698de964233735a000768bdf2c561c1bde36 100644 (file)
@@ -302,6 +302,27 @@ struct timeval {
 #endif
 
 
+/*
+ * Macro WHILE_FALSE may be used to build single-iteration do-while loops,
+ * avoiding compiler warnings. Mostly intended for other macro definitions.
+ */
+
+#define WHILE_FALSE  while(0)
+
+#if defined(_MSC_VER) && !defined(__POCC__)
+#  undef WHILE_FALSE
+#  if (_MSC_VER < 1500)
+#    define WHILE_FALSE  while(1, 0)
+#  else
+#    define WHILE_FALSE \
+__pragma(warning(push)) \
+__pragma(warning(disable:4127)) \
+while(0) \
+__pragma(warning(pop))
+#  endif
+#endif
+
+
 /*
  * Typedef to 'int' if sig_atomic_t is not an available 'typedefed' type.
  */
@@ -339,7 +360,7 @@ typedef int sig_atomic_t;
 #ifdef DEBUGBUILD
 #define DEBUGF(x) x
 #else
-#define DEBUGF(x) do { } while (0)
+#define DEBUGF(x) do { } WHILE_FALSE
 #endif
 
 
@@ -350,7 +371,7 @@ typedef int sig_atomic_t;
 #if defined(DEBUGBUILD) && defined(HAVE_ASSERT_H)
 #define DEBUGASSERT(x) assert(x)
 #else
-#define DEBUGASSERT(x) do { } while (0)
+#define DEBUGASSERT(x) do { } WHILE_FALSE
 #endif
 
 
index b0ae8f02aa6e149977c47dd6854556cb074c2a53..dbb06dbd50e6b0f1304fe677380c4b0f5113d763 100644 (file)
@@ -800,6 +800,9 @@ static CURLcode readwrite_upload(struct SessionHandle *data,
   /*
    * We loop here to do the READ and SEND loop until we run out of
    * data to send or until we get EWOULDBLOCK back
+   *
+   * FIXME: above comment is misleading. Currently no looping is
+   * actually done in do-while loop below.
    */
   do {
 
@@ -971,7 +974,7 @@ static CURLcode readwrite_upload(struct SessionHandle *data,
 
     Curl_pgrsSetUploadCounter(data, k->writebytecount);
 
-  } while(0); /* just to break out from! */
+  } WHILE_FALSE; /* just to break out from! */
 
   return CURLE_OK;
 }
index 4d39f2e01d81b939271747d89c9028a89fd857c8..23ca7a5d4d42aa3fd4bb0a010897edde84dd672a 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -252,12 +252,6 @@ static const struct Curl_handler Curl_handler_dummy = {
   PROTOPT_NONE                          /* flags */
 };
 
-void Curl_safefree(void *ptr)
-{
-  if(ptr)
-    free(ptr);
-}
-
 static void close_connections(struct SessionHandle *data)
 {
   /* Loop through all open connections and kill them one by one */
index 677e639543666c0cda02ab24670d14f507383e1f..62e3ef3ef33394f6be896b67206ee3c64239af37 100644 (file)
--- a/lib/url.h
+++ b/lib/url.h
@@ -42,7 +42,6 @@ CURLcode Curl_disconnect(struct connectdata *, bool dead_connection);
 CURLcode Curl_protocol_connect(struct connectdata *conn, bool *done);
 CURLcode Curl_protocol_connecting(struct connectdata *conn, bool *done);
 CURLcode Curl_protocol_doing(struct connectdata *conn, bool *done);
-void Curl_safefree(void *ptr);
 CURLcode Curl_setup_conn(struct connectdata *conn,
                          bool *protocol_done);