205
216
size_t size = sizeof(struct memdebug)+wantedsize;
218
assert(wantedsize != 0);
207
220
if(countcheck("realloc", line, source))
223
#ifdef __INTEL_COMPILER
224
# pragma warning(push)
225
# pragma warning(disable:1684)
226
/* 1684: conversion from pointer to same-sized integral type */
211
mem = (struct memdebug *)((char *)ptr - offsetof(struct memdebug, mem));
230
mem = (void *)((char *)ptr - offsetof(struct memdebug, mem));
232
#ifdef __INTEL_COMPILER
233
# pragma warning(pop)
213
236
mem = (Curl_crealloc)(mem, size);
215
fprintf(logfile, "MEM %s:%d realloc(%p, %zu) = %p\n",
216
source, line, ptr, wantedsize, mem?mem->mem:NULL);
238
curl_memlog("MEM %s:%d realloc(%p, %zu) = %p\n",
239
source, line, ptr, wantedsize, mem?mem->mem:NULL);
219
242
mem->size = wantedsize;
237
270
/* free for real */
238
271
(Curl_cfree)(mem);
241
fprintf(logfile, "MEM %s:%d free(%p)\n", source, line, ptr);
274
curl_memlog("MEM %s:%d free(%p)\n", source, line, ptr);
244
int curl_socket(int domain, int type, int protocol, int line,
277
curl_socket_t curl_socket(int domain, int type, int protocol,
278
int line, const char *source)
247
int sockfd=socket(domain, type, protocol);
248
if(logfile && (sockfd!=-1))
249
fprintf(logfile, "FD %s:%d socket() = %d\n",
250
source, line, sockfd);
280
const char *fmt = (sizeof(curl_socket_t) == sizeof(int)) ?
281
"FD %s:%d socket() = %d\n" :
282
(sizeof(curl_socket_t) == sizeof(long)) ?
283
"FD %s:%d socket() = %ld\n" :
284
"FD %s:%d socket() = %zd\n" ;
286
curl_socket_t sockfd = socket(domain, type, protocol);
287
if(source && (sockfd != CURL_SOCKET_BAD))
288
curl_memlog(fmt, source, line, sockfd);
254
int curl_accept(int s, void *saddr, void *saddrlen,
255
int line, const char *source)
292
curl_socket_t curl_accept(curl_socket_t s, void *saddr, void *saddrlen,
293
int line, const char *source)
295
const char *fmt = (sizeof(curl_socket_t) == sizeof(int)) ?
296
"FD %s:%d accept() = %d\n" :
297
(sizeof(curl_socket_t) == sizeof(long)) ?
298
"FD %s:%d accept() = %ld\n" :
299
"FD %s:%d accept() = %zd\n" ;
257
301
struct sockaddr *addr = (struct sockaddr *)saddr;
258
302
curl_socklen_t *addrlen = (curl_socklen_t *)saddrlen;
259
int sockfd=accept(s, addr, addrlen);
261
fprintf(logfile, "FD %s:%d accept() = %d\n",
262
source, line, sockfd);
303
curl_socket_t sockfd = accept(s, addr, addrlen);
304
if(source && (sockfd != CURL_SOCKET_BAD))
305
curl_memlog(fmt, source, line, sockfd);
266
309
/* separate function to allow libcurl to mark a "faked" close */
267
void curl_mark_sclose(int sockfd, int line, const char *source)
310
void curl_mark_sclose(curl_socket_t sockfd, int line, const char *source)
270
fprintf(logfile, "FD %s:%d sclose(%d)\n",
271
source, line, sockfd);
312
const char *fmt = (sizeof(curl_socket_t) == sizeof(int)) ?
313
"FD %s:%d sclose(%d)\n" :
314
(sizeof(curl_socket_t) == sizeof(long)) ?
315
"FD %s:%d sclose(%ld)\n" :
316
"FD %s:%d sclose(%zd)\n" ;
319
curl_memlog(fmt, source, line, sockfd);
274
322
/* this is our own defined way to close sockets on *ALL* platforms */
275
int curl_sclose(int sockfd, int line, const char *source)
323
int curl_sclose(curl_socket_t sockfd, int line, const char *source)
277
325
int res=sclose(sockfd);
278
326
curl_mark_sclose(sockfd, line, source);
283
331
int line, const char *source)
285
333
FILE *res=fopen(file, mode);
287
fprintf(logfile, "FILE %s:%d fopen(\"%s\",\"%s\") = %p\n",
288
source, line, file, mode, res);
335
curl_memlog("FILE %s:%d fopen(\"%s\",\"%s\") = %p\n",
336
source, line, file, mode, res);
294
342
int line, const char *source)
296
344
FILE *res=fdopen(filedes, mode);
298
fprintf(logfile, "FILE %s:%d fdopen(\"%d\",\"%s\") = %p\n",
299
source, line, filedes, mode, res);
346
curl_memlog("FILE %s:%d fdopen(\"%d\",\"%s\") = %p\n",
347
source, line, filedes, mode, res);
308
DEBUGASSERT(file != NULL);
356
assert(file != NULL);
310
358
res=fclose(file);
312
fprintf(logfile, "FILE %s:%d fclose(%p)\n",
360
curl_memlog("FILE %s:%d fclose(%p)\n",
365
#define LOGLINE_BUFSIZE 1024
367
/* this does the writting to the memory tracking log file */
368
void curl_memlog(const char *format, ...)
377
buf = (Curl_cmalloc)(LOGLINE_BUFSIZE);
381
va_start(ap, format);
382
nchars = vsnprintf(buf, LOGLINE_BUFSIZE, format, ap);
385
if(nchars > LOGLINE_BUFSIZE - 1)
386
nchars = LOGLINE_BUFSIZE - 1;
389
fwrite(buf, 1, nchars, logfile);
316
394
#endif /* CURLDEBUG */