Line | Count | Source |
1 | | /*************************************************************************** |
2 | | * _ _ ____ _ |
3 | | * Project ___| | | | _ \| | |
4 | | * / __| | | | |_) | | |
5 | | * | (__| |_| | _ <| |___ |
6 | | * \___|\___/|_| \_\_____| |
7 | | * |
8 | | * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. |
9 | | * |
10 | | * This software is licensed as described in the file COPYING, which |
11 | | * you should have received as part of this distribution. The terms |
12 | | * are also available at https://curl.se/docs/copyright.html. |
13 | | * |
14 | | * You may opt to use, copy, modify, merge, publish, distribute and/or sell |
15 | | * copies of the Software, and permit persons to whom the Software is |
16 | | * furnished to do so, under the terms of the COPYING file. |
17 | | * |
18 | | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
19 | | * KIND, either express or implied. |
20 | | * |
21 | | * SPDX-License-Identifier: curl |
22 | | * |
23 | | ***************************************************************************/ |
24 | | #include "curl_setup.h" |
25 | | |
26 | | #ifdef CURL_MEMDEBUG |
27 | | |
28 | | #include <stddef.h> /* for offsetof() */ |
29 | | |
30 | | #include "urldata.h" |
31 | | #include "curl_threads.h" |
32 | | #include "curlx/win32-fopen.h" /* for CURLX_FOPEN_*() */ |
33 | | |
34 | | #ifdef USE_BACKTRACE |
35 | | #include <backtrace.h> |
36 | | #endif |
37 | | |
38 | | struct memdebug { |
39 | | size_t size; |
40 | | size_t padding; /* keep mem aligned like malloc(), up to 16 */ |
41 | | union { |
42 | | curl_off_t o; |
43 | | double d; |
44 | | void *p; |
45 | | } mem[1]; |
46 | | /* I am hoping this is the thing with the strictest alignment |
47 | | * requirements. That also means we waste some space :-( */ |
48 | | }; |
49 | | |
50 | | /* |
51 | | * Note that these debug functions are simple and they are meant to remain so. |
52 | | * For advanced analysis, record a log file and write perl scripts to analyze |
53 | | * them! |
54 | | * |
55 | | * Do not use these with multi-threaded test programs! |
56 | | */ |
57 | | |
58 | | FILE *curl_dbg_logfile = NULL; |
59 | | static bool registered_cleanup = FALSE; /* atexit registered cleanup */ |
60 | | static bool memlimit = FALSE; /* enable memory limit */ |
61 | | static long memsize = 0; /* set number of mallocs allowed */ |
62 | | #ifdef USE_BACKTRACE |
63 | | static struct backtrace_state *btstate; |
64 | | #endif |
65 | | |
66 | | static char membuf[10000]; |
67 | | static size_t memwidx = 0; /* write index */ |
68 | | |
69 | | #ifdef USE_MUTEX |
70 | | static bool dbg_mutex_init = 0; |
71 | | static curl_mutex_t dbg_mutex; |
72 | | #endif |
73 | | |
74 | | static bool curl_dbg_lock(void) |
75 | 126k | { |
76 | 126k | #ifdef USE_MUTEX |
77 | 126k | if(dbg_mutex_init) { |
78 | 0 | Curl_mutex_acquire(&dbg_mutex); |
79 | 0 | return TRUE; |
80 | 0 | } |
81 | 126k | #endif |
82 | 126k | return FALSE; |
83 | 126k | } |
84 | | |
85 | | static void curl_dbg_unlock(bool was_locked) |
86 | 126k | { |
87 | 126k | #ifdef USE_MUTEX |
88 | 126k | if(was_locked) |
89 | 0 | Curl_mutex_release(&dbg_mutex); |
90 | | #else |
91 | | (void)was_locked; |
92 | | #endif |
93 | 126k | } |
94 | | |
95 | | static void curl_dbg_log_locked(const char *format, ...) CURL_PRINTF(1, 2); |
96 | | |
97 | | /* LeakSantizier (LSAN) calls _exit() instead of exit() when a leak is detected |
98 | | on exit so the logfile must be closed explicitly or data could be lost. |
99 | | Though _exit() does not call atexit handlers such as this, LSAN's call to |
100 | | _exit() comes after the atexit handlers are called. curl/curl#6620 */ |
101 | | static void curl_dbg_cleanup(void) |
102 | 0 | { |
103 | 0 | bool locked = curl_dbg_lock(); |
104 | 0 | if(curl_dbg_logfile && |
105 | 0 | curl_dbg_logfile != stderr && |
106 | 0 | curl_dbg_logfile != stdout) { |
107 | 0 | if(memwidx) |
108 | 0 | fwrite(membuf, 1, memwidx, curl_dbg_logfile); |
109 | | /* !checksrc! disable BANNEDFUNC 1 */ |
110 | 0 | fclose(curl_dbg_logfile); |
111 | 0 | } |
112 | 0 | curl_dbg_logfile = NULL; |
113 | 0 | curl_dbg_unlock(locked); |
114 | 0 | #ifdef USE_MUTEX |
115 | 0 | if(dbg_mutex_init) { |
116 | 0 | Curl_mutex_destroy(&dbg_mutex); |
117 | 0 | dbg_mutex_init = FALSE; |
118 | 0 | } |
119 | 0 | #endif |
120 | 0 | } |
121 | | |
122 | | #ifdef USE_BACKTRACE |
123 | | static void error_bt_callback(void *data, const char *message, |
124 | | int error_number) |
125 | | { |
126 | | (void)data; |
127 | | if(error_number == -1) |
128 | | curl_dbg_log("compile with -g\n\n"); |
129 | | else |
130 | | curl_dbg_log("Backtrace error %d: %s\n", error_number, message); |
131 | | } |
132 | | |
133 | | static int full_callback(void *data, uintptr_t pc, const char *pathname, |
134 | | int line_number, const char *function) |
135 | | { |
136 | | (void)data; |
137 | | (void)pc; |
138 | | if(pathname || function || line_number) |
139 | | curl_dbg_log("BT %s:%d -- %s\n", pathname, line_number, function); |
140 | | return 0; |
141 | | } |
142 | | |
143 | | static void dump_bt(void) |
144 | | { |
145 | | backtrace_full(btstate, 0, full_callback, error_bt_callback, NULL); |
146 | | } |
147 | | #else |
148 | | #define dump_bt() /* nothing to do */ |
149 | | #endif |
150 | | |
151 | | /* this sets the log filename */ |
152 | | void curl_dbg_memdebug(const char *logname) |
153 | 0 | { |
154 | 0 | if(!curl_dbg_logfile) { |
155 | 0 | if(logname && *logname) |
156 | 0 | curl_dbg_logfile = CURLX_FOPEN_LOW(logname, FOPEN_WRITETEXT); |
157 | | #ifdef MEMDEBUG_LOG_SYNC |
158 | | /* Flush the log file after every line so the log is not lost in a crash */ |
159 | | if(curl_dbg_logfile) |
160 | | setbuf(curl_dbg_logfile, (char *)NULL); |
161 | | #endif |
162 | 0 | } |
163 | 0 | #ifdef USE_MUTEX |
164 | 0 | if(!dbg_mutex_init) { |
165 | 0 | dbg_mutex_init = TRUE; |
166 | 0 | Curl_mutex_init(&dbg_mutex); |
167 | 0 | } |
168 | 0 | #endif |
169 | | #ifdef USE_BACKTRACE |
170 | | btstate = backtrace_create_state(NULL, 0, error_bt_callback, NULL); |
171 | | #endif |
172 | 0 | if(!registered_cleanup) |
173 | 0 | registered_cleanup = !atexit(curl_dbg_cleanup); |
174 | 0 | } |
175 | | |
176 | | /* This function sets the number of malloc() calls that should return |
177 | | successfully! */ |
178 | | void curl_dbg_memlimit(long limit) |
179 | 0 | { |
180 | 0 | if(!memlimit) { |
181 | 0 | memlimit = TRUE; |
182 | 0 | memsize = limit; |
183 | 0 | } |
184 | 0 | } |
185 | | |
186 | | /* returns TRUE if this is not allowed! */ |
187 | | static bool countcheck(const char *func, int line, const char *source) |
188 | 890k | { |
189 | | /* if source is NULL, then the call is made internally and this check |
190 | | should not be made */ |
191 | 890k | if(memlimit && source) { |
192 | 0 | if(!memsize) { |
193 | | /* log to file */ |
194 | 0 | curl_dbg_log("LIMIT %s:%d %s reached memlimit\n", source, line, func); |
195 | | /* log to stderr also */ |
196 | 0 | curl_mfprintf(stderr, "LIMIT %s:%d %s reached memlimit\n", |
197 | 0 | source, line, func); |
198 | 0 | dump_bt(); |
199 | 0 | fflush(curl_dbg_logfile); /* because it might crash now */ |
200 | | /* !checksrc! disable ERRNOVAR 1 */ |
201 | 0 | errno = ENOMEM; |
202 | 0 | return TRUE; /* RETURN ERROR! */ |
203 | 0 | } |
204 | 0 | else |
205 | 0 | memsize--; /* countdown */ |
206 | 0 | } |
207 | | |
208 | 890k | return FALSE; /* allow this */ |
209 | 890k | } |
210 | | |
211 | | ALLOC_FUNC |
212 | | void *curl_dbg_malloc(size_t wantedsize, int line, const char *source) |
213 | 261k | { |
214 | 261k | struct memdebug *mem; |
215 | 261k | size_t size; |
216 | | |
217 | 261k | DEBUGASSERT(wantedsize != 0); |
218 | | |
219 | 261k | if(countcheck("malloc", line, source)) |
220 | 0 | return NULL; |
221 | | |
222 | | /* alloc at least 64 bytes */ |
223 | 261k | size = sizeof(struct memdebug) + wantedsize; |
224 | | |
225 | 261k | mem = Curl_cmalloc(size); |
226 | 261k | if(mem) { |
227 | 260k | mem->size = wantedsize; |
228 | 260k | } |
229 | | |
230 | 261k | if(source) |
231 | 189k | curl_dbg_log("MEM %s:%d malloc(%zu) = %p\n", |
232 | 189k | source, line, wantedsize, |
233 | 189k | mem ? (void *)mem->mem : (void *)0); |
234 | | |
235 | 261k | return mem ? mem->mem : NULL; |
236 | 261k | } |
237 | | |
238 | | ALLOC_FUNC |
239 | | void *curl_dbg_calloc(size_t wanted_elements, size_t wanted_size, |
240 | | int line, const char *source) |
241 | 420k | { |
242 | 420k | struct memdebug *mem; |
243 | 420k | size_t size, user_size; |
244 | | |
245 | 420k | DEBUGASSERT(wanted_elements != 0); |
246 | 420k | DEBUGASSERT(wanted_size != 0); |
247 | | |
248 | 420k | if(countcheck("calloc", line, source)) |
249 | 0 | return NULL; |
250 | | |
251 | | /* alloc at least 64 bytes */ |
252 | 420k | user_size = wanted_size * wanted_elements; |
253 | 420k | size = sizeof(struct memdebug) + user_size; |
254 | | |
255 | 420k | mem = Curl_ccalloc(1, size); |
256 | 420k | if(mem) |
257 | 419k | mem->size = user_size; |
258 | | |
259 | 420k | if(source) |
260 | 420k | curl_dbg_log("MEM %s:%d calloc(%zu,%zu) = %p\n", |
261 | 420k | source, line, wanted_elements, wanted_size, |
262 | 420k | mem ? (void *)mem->mem : (void *)0); |
263 | | |
264 | 420k | return mem ? mem->mem : NULL; |
265 | 420k | } |
266 | | |
267 | | ALLOC_FUNC |
268 | | char *curl_dbg_strdup(const char *str, int line, const char *source) |
269 | 71.9k | { |
270 | 71.9k | char *mem; |
271 | 71.9k | size_t len; |
272 | | |
273 | 71.9k | DEBUGASSERT(str); |
274 | | |
275 | 71.9k | if(countcheck("strdup", line, source)) |
276 | 0 | return NULL; |
277 | | |
278 | 71.9k | len = strlen(str) + 1; |
279 | | |
280 | 71.9k | mem = curl_dbg_malloc(len, 0, NULL); /* NULL prevents logging */ |
281 | 71.9k | if(mem) |
282 | 71.7k | memcpy(mem, str, len); |
283 | | |
284 | 71.9k | if(source) |
285 | 71.9k | curl_dbg_log("MEM %s:%d strdup(%p) (%zu) = %p\n", |
286 | 71.9k | source, line, (const void *)str, len, (const void *)mem); |
287 | | |
288 | 71.9k | return mem; |
289 | 71.9k | } |
290 | | |
291 | | #if defined(_WIN32) && defined(UNICODE) |
292 | | ALLOC_FUNC |
293 | | wchar_t *curl_dbg_wcsdup(const wchar_t *str, int line, const char *source) |
294 | | { |
295 | | wchar_t *mem; |
296 | | size_t wsiz, bsiz; |
297 | | |
298 | | DEBUGASSERT(str); |
299 | | |
300 | | if(countcheck("wcsdup", line, source)) |
301 | | return NULL; |
302 | | |
303 | | wsiz = wcslen(str) + 1; |
304 | | bsiz = wsiz * sizeof(wchar_t); |
305 | | |
306 | | mem = curl_dbg_malloc(bsiz, 0, NULL); /* NULL prevents logging */ |
307 | | if(mem) |
308 | | memcpy(mem, str, bsiz); |
309 | | |
310 | | if(source) |
311 | | curl_dbg_log("MEM %s:%d wcsdup(%p) (%zu) = %p\n", |
312 | | source, line, (const void *)str, bsiz, (void *)mem); |
313 | | |
314 | | return mem; |
315 | | } |
316 | | #endif |
317 | | |
318 | | /* We provide a realloc() that accepts a NULL as pointer, which then |
319 | | performs a malloc(). In order to work with ares. */ |
320 | | void *curl_dbg_realloc(void *ptr, size_t wantedsize, |
321 | | int line, const char *source) |
322 | 126k | { |
323 | 126k | struct memdebug *mem = NULL; |
324 | 126k | bool was_locked; |
325 | | |
326 | 126k | size_t size = sizeof(struct memdebug) + wantedsize; |
327 | | |
328 | 126k | DEBUGASSERT(wantedsize != 0); |
329 | | |
330 | 126k | if(countcheck("realloc", line, source)) |
331 | 0 | return NULL; |
332 | | |
333 | | /* need to realloc under lock, as we get out-of-order log |
334 | | * entries otherwise, since another thread might alloc the |
335 | | * memory released by realloc() before otherwise would log it. */ |
336 | 126k | was_locked = curl_dbg_lock(); |
337 | | #ifdef __INTEL_COMPILER |
338 | | # pragma warning(push) |
339 | | # pragma warning(disable:1684) |
340 | | /* 1684: conversion from pointer to same-sized integral type */ |
341 | | #endif |
342 | | |
343 | 126k | if(ptr) |
344 | 24.6k | mem = (void *)((char *)ptr - offsetof(struct memdebug, mem)); |
345 | | |
346 | | #ifdef __INTEL_COMPILER |
347 | | # pragma warning(pop) |
348 | | #endif |
349 | | |
350 | 126k | mem = Curl_crealloc(mem, size); |
351 | 126k | if(source) |
352 | 126k | curl_dbg_log_locked("MEM %s:%d realloc(%p, %zu) = %p\n", |
353 | 126k | source, line, (void *)ptr, wantedsize, |
354 | 126k | mem ? (void *)mem->mem : (void *)0); |
355 | | |
356 | 126k | curl_dbg_unlock(was_locked); |
357 | 126k | if(mem) { |
358 | 126k | mem->size = wantedsize; |
359 | 126k | return mem->mem; |
360 | 126k | } |
361 | | |
362 | 274 | return NULL; |
363 | 126k | } |
364 | | |
365 | | void curl_dbg_free(void *ptr, int line, const char *source) |
366 | 3.92M | { |
367 | 3.92M | if(ptr) { |
368 | 782k | struct memdebug *mem; |
369 | | |
370 | 782k | if(source) |
371 | 782k | curl_dbg_log("MEM %s:%d free(%p)\n", source, line, (void *)ptr); |
372 | | |
373 | | #ifdef __INTEL_COMPILER |
374 | | # pragma warning(push) |
375 | | # pragma warning(disable:1684) |
376 | | /* 1684: conversion from pointer to same-sized integral type */ |
377 | | #endif |
378 | | |
379 | 782k | mem = (void *)((char *)ptr - offsetof(struct memdebug, mem)); |
380 | | |
381 | | #ifdef __INTEL_COMPILER |
382 | | # pragma warning(pop) |
383 | | #endif |
384 | | |
385 | | /* free for real */ |
386 | 782k | Curl_cfree(mem); |
387 | 782k | } |
388 | 3.92M | } |
389 | | |
390 | | curl_socket_t curl_dbg_socket(int domain, int type, int protocol, |
391 | | int line, const char *source) |
392 | 9.77k | { |
393 | 9.77k | curl_socket_t sockfd; |
394 | | |
395 | 9.77k | if(countcheck("socket", line, source)) |
396 | 0 | return CURL_SOCKET_BAD; |
397 | | |
398 | | /* !checksrc! disable BANNEDFUNC 1 */ |
399 | 9.77k | sockfd = socket(domain, type, protocol); |
400 | | |
401 | 9.77k | if(source && (sockfd != CURL_SOCKET_BAD)) |
402 | 9.77k | curl_dbg_log("FD %s:%d socket() = %" FMT_SOCKET_T "\n", |
403 | 9.77k | source, line, sockfd); |
404 | | |
405 | 9.77k | return sockfd; |
406 | 9.77k | } |
407 | | |
408 | | #ifdef HAVE_SOCKETPAIR |
409 | | int curl_dbg_socketpair(int domain, int type, int protocol, |
410 | | curl_socket_t socket_vector[2], |
411 | | int line, const char *source) |
412 | 0 | { |
413 | | /* !checksrc! disable BANNEDFUNC 1 */ |
414 | 0 | int res = socketpair(domain, type, protocol, socket_vector); |
415 | |
|
416 | 0 | if(source && (res == 0)) |
417 | 0 | curl_dbg_log("FD %s:%d socketpair() = " |
418 | 0 | "%" FMT_SOCKET_T " %" FMT_SOCKET_T "\n", |
419 | 0 | source, line, socket_vector[0], socket_vector[1]); |
420 | |
|
421 | 0 | return res; |
422 | 0 | } |
423 | | #endif |
424 | | |
425 | | curl_socket_t curl_dbg_accept(curl_socket_t s, void *saddr, void *saddrlen, |
426 | | int line, const char *source) |
427 | 0 | { |
428 | 0 | struct sockaddr *addr = (struct sockaddr *)saddr; |
429 | 0 | curl_socklen_t *addrlen = (curl_socklen_t *)saddrlen; |
430 | | |
431 | | /* !checksrc! disable BANNEDFUNC 1 */ |
432 | 0 | curl_socket_t sockfd = accept(s, addr, addrlen); |
433 | |
|
434 | 0 | if(source && (sockfd != CURL_SOCKET_BAD)) |
435 | 0 | curl_dbg_log("FD %s:%d accept() = %" FMT_SOCKET_T "\n", |
436 | 0 | source, line, sockfd); |
437 | |
|
438 | 0 | return sockfd; |
439 | 0 | } |
440 | | |
441 | | #ifdef HAVE_ACCEPT4 |
442 | | curl_socket_t curl_dbg_accept4(curl_socket_t s, void *saddr, void *saddrlen, |
443 | | int flags, |
444 | | int line, const char *source) |
445 | 0 | { |
446 | 0 | struct sockaddr *addr = (struct sockaddr *)saddr; |
447 | 0 | curl_socklen_t *addrlen = (curl_socklen_t *)saddrlen; |
448 | | |
449 | | /* !checksrc! disable BANNEDFUNC 1 */ |
450 | 0 | curl_socket_t sockfd = accept4(s, addr, addrlen, flags); |
451 | |
|
452 | 0 | if(source && (sockfd != CURL_SOCKET_BAD)) |
453 | 0 | curl_dbg_log("FD %s:%d accept() = %" FMT_SOCKET_T "\n", |
454 | 0 | source, line, sockfd); |
455 | |
|
456 | 0 | return sockfd; |
457 | 0 | } |
458 | | #endif |
459 | | |
460 | | /* separate function to allow libcurl to mark a "faked" close */ |
461 | | void curl_dbg_mark_sclose(curl_socket_t sockfd, int line, const char *source) |
462 | 18.9k | { |
463 | 18.9k | if(source) |
464 | 18.9k | curl_dbg_log("FD %s:%d sclose(%" FMT_SOCKET_T ")\n", |
465 | 18.9k | source, line, sockfd); |
466 | 18.9k | } |
467 | | |
468 | | /* this is our own defined way to close sockets on *ALL* platforms */ |
469 | | int curl_dbg_sclose(curl_socket_t sockfd, int line, const char *source) |
470 | 18.9k | { |
471 | 18.9k | curl_dbg_mark_sclose(sockfd, line, source); |
472 | 18.9k | return CURL_SCLOSE(sockfd); |
473 | 18.9k | } |
474 | | |
475 | | ALLOC_FUNC |
476 | | FILE *curl_dbg_fopen(const char *file, const char *mode, |
477 | | int line, const char *source) |
478 | 58.4k | { |
479 | 58.4k | FILE *res = CURLX_FOPEN_LOW(file, mode); |
480 | 58.4k | if(source) |
481 | 58.4k | curl_dbg_log("FILE %s:%d fopen(\"%s\",\"%s\") = %p\n", |
482 | 58.4k | source, line, file, mode, (void *)res); |
483 | | |
484 | 58.4k | return res; |
485 | 58.4k | } |
486 | | |
487 | | ALLOC_FUNC |
488 | | FILE *curl_dbg_freopen(const char *file, const char *mode, FILE *fh, |
489 | | int line, const char *source) |
490 | 0 | { |
491 | 0 | FILE *res = CURLX_FREOPEN_LOW(file, mode, fh); |
492 | 0 | if(source) |
493 | 0 | curl_dbg_log("FILE %s:%d freopen(\"%s\",\"%s\",%p) = %p\n", |
494 | 0 | source, line, file, mode, (void *)fh, (void *)res); |
495 | |
|
496 | 0 | return res; |
497 | 0 | } |
498 | | |
499 | | ALLOC_FUNC |
500 | | FILE *curl_dbg_fdopen(int filedes, const char *mode, |
501 | | int line, const char *source) |
502 | 0 | { |
503 | 0 | FILE *res = CURLX_FDOPEN_LOW(filedes, mode); |
504 | 0 | if(source) |
505 | 0 | curl_dbg_log("FILE %s:%d fdopen(\"%d\",\"%s\") = %p\n", |
506 | 0 | source, line, filedes, mode, (void *)res); |
507 | 0 | return res; |
508 | 0 | } |
509 | | |
510 | | int curl_dbg_fclose(FILE *file, int line, const char *source) |
511 | 58.4k | { |
512 | 58.4k | int res; |
513 | | |
514 | 58.4k | DEBUGASSERT(file); |
515 | | |
516 | 58.4k | if(source) |
517 | 58.4k | curl_dbg_log("FILE %s:%d fclose(%p)\n", source, line, (void *)file); |
518 | | |
519 | | /* !checksrc! disable BANNEDFUNC 1 */ |
520 | 58.4k | res = fclose(file); |
521 | | |
522 | 58.4k | return res; |
523 | 58.4k | } |
524 | | |
525 | | static void curl_dbg_vlog(const char * const fmt, |
526 | | va_list ap) CURL_PRINTF(1, 0); |
527 | | |
528 | | static void curl_dbg_vlog(const char * const fmt, va_list ap) |
529 | 0 | { |
530 | 0 | char buf[1024]; |
531 | 0 | size_t nchars = curl_mvsnprintf(buf, sizeof(buf), fmt, ap); |
532 | |
|
533 | 0 | if(nchars > (int)sizeof(buf) - 1) |
534 | 0 | nchars = (int)sizeof(buf) - 1; |
535 | |
|
536 | 0 | if(nchars > 0) { |
537 | 0 | if(sizeof(membuf) - nchars < memwidx) { |
538 | | /* flush */ |
539 | 0 | fwrite(membuf, 1, memwidx, curl_dbg_logfile); |
540 | 0 | fflush(curl_dbg_logfile); |
541 | 0 | memwidx = 0; |
542 | 0 | } |
543 | 0 | if(memwidx) { |
544 | | /* the previous line ends with a newline */ |
545 | 0 | DEBUGASSERT(membuf[memwidx - 1] == '\n'); |
546 | 0 | } |
547 | 0 | memcpy(&membuf[memwidx], buf, nchars); |
548 | 0 | memwidx += nchars; |
549 | 0 | } |
550 | 0 | } |
551 | | |
552 | | static void curl_dbg_log_locked(const char *format, ...) |
553 | 126k | { |
554 | 126k | va_list ap; |
555 | | |
556 | 126k | if(!curl_dbg_logfile) |
557 | 126k | return; |
558 | | |
559 | 126k | va_start(ap, format); |
560 | 0 | curl_dbg_vlog(format, ap); |
561 | 0 | va_end(ap); |
562 | 0 | } |
563 | | |
564 | | /* this does the writing to the memory tracking log file */ |
565 | | void curl_dbg_log(const char *format, ...) |
566 | 1.60M | { |
567 | 1.60M | bool was_locked; |
568 | 1.60M | va_list ap; |
569 | | |
570 | 1.60M | if(!curl_dbg_logfile) |
571 | 1.60M | return; |
572 | | |
573 | 1 | was_locked = curl_dbg_lock(); |
574 | 1 | va_start(ap, format); |
575 | 1 | curl_dbg_vlog(format, ap); |
576 | | va_end(ap); |
577 | 1 | curl_dbg_unlock(was_locked); |
578 | 1 | } |
579 | | |
580 | | #endif /* CURL_MEMDEBUG */ |