Commit 9194e170 authored by Yang Tse's avatar Yang Tse
Browse files

MemoryTracking: fix logging of free() calls done where Curl_safefree is called

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.
parent 749dbfbc
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
#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 */
+1 −1
Original line number Diff line number Diff line
@@ -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  {
+3 −3
Original line number Diff line number Diff line
@@ -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) {
+2 −2
Original line number Diff line number Diff line
@@ -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 */
+23 −2
Original line number Diff line number Diff line
@@ -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


Loading