diff options
Diffstat (limited to 'lib/memdebug.c')
-rw-r--r-- | lib/memdebug.c | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/lib/memdebug.c b/lib/memdebug.c index 15e86616..8c9fe950 100644 --- a/lib/memdebug.c +++ b/lib/memdebug.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -35,10 +35,6 @@ #include "curl_memory.h" #include "memdebug.h" -#ifndef HAVE_ASSERT_H -# define assert(x) Curl_nop_stmt -#endif - /* * Until 2011-08-17 libcurl's Memory Tracking feature also performed * automatic malloc and free filling operations using 0xA5 and 0x13 @@ -119,7 +115,8 @@ void curl_memdebug(const char *logname) logfile = stderr; #ifdef MEMDEBUG_LOG_SYNC /* Flush the log file after every line so the log isn't lost in a crash */ - setbuf(logfile, (char *)NULL); + if(logfile) + setbuf(logfile, (char *)NULL); #endif } } @@ -150,7 +147,7 @@ static bool countcheck(const char *func, int line, const char *source) source, line, func); fflush(logfile); /* because it might crash now */ } - SET_ERRNO(ENOMEM); + errno = ENOMEM; return TRUE; /* RETURN ERROR! */ } else @@ -167,7 +164,7 @@ void *curl_domalloc(size_t wantedsize, int line, const char *source) struct memdebug *mem; size_t size; - assert(wantedsize != 0); + DEBUGASSERT(wantedsize != 0); if(countcheck("malloc", line, source)) return NULL; @@ -196,8 +193,8 @@ void *curl_docalloc(size_t wanted_elements, size_t wanted_size, struct memdebug *mem; size_t size, user_size; - assert(wanted_elements != 0); - assert(wanted_size != 0); + DEBUGASSERT(wanted_elements != 0); + DEBUGASSERT(wanted_size != 0); if(countcheck("calloc", line, source)) return NULL; @@ -223,7 +220,7 @@ char *curl_dostrdup(const char *str, int line, const char *source) char *mem; size_t len; - assert(str != NULL); + DEBUGASSERT(str != NULL); if(countcheck("strdup", line, source)) return NULL; @@ -236,7 +233,7 @@ char *curl_dostrdup(const char *str, int line, const char *source) if(source) curl_memlog("MEM %s:%d strdup(%p) (%zu) = %p\n", - source, line, (void *)str, len, (void *)mem); + source, line, (const void *)str, len, (const void *)mem); return mem; } @@ -247,7 +244,7 @@ wchar_t *curl_dowcsdup(const wchar_t *str, int line, const char *source) wchar_t *mem; size_t wsiz, bsiz; - assert(str != NULL); + DEBUGASSERT(str != NULL); if(countcheck("wcsdup", line, source)) return NULL; @@ -276,7 +273,7 @@ void *curl_dorealloc(void *ptr, size_t wantedsize, size_t size = sizeof(struct memdebug)+wantedsize; - assert(wantedsize != 0); + DEBUGASSERT(wantedsize != 0); if(countcheck("realloc", line, source)) return NULL; @@ -445,7 +442,7 @@ int curl_fclose(FILE *file, int line, const char *source) { int res; - assert(file != NULL); + DEBUGASSERT(file != NULL); res=fclose(file); @@ -458,7 +455,7 @@ int curl_fclose(FILE *file, int line, const char *source) #define LOGLINE_BUFSIZE 1024 -/* this does the writting to the memory tracking log file */ +/* this does the writing to the memory tracking log file */ void curl_memlog(const char *format, ...) { char *buf; @@ -480,7 +477,7 @@ void curl_memlog(const char *format, ...) nchars = LOGLINE_BUFSIZE - 1; if(nchars > 0) - fwrite(buf, 1, nchars, logfile); + fwrite(buf, 1, (size_t)nchars, logfile); (Curl_cfree)(buf); } |