~ubuntu-branches/ubuntu/lucid/curl/lucid-201101212007

« back to all changes in this revision

Viewing changes to lib/memdebug.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-05-16 15:16:54 UTC
  • mto: (3.1.1 lenny) (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: james.westby@ubuntu.com-20070516151654-x9nkigtr2j0i8d0v
Tags: upstream-7.16.2
ImportĀ upstreamĀ versionĀ 7.16.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 *                            | (__| |_| |  _ <| |___
7
7
 *                             \___|\___/|_| \_\_____|
8
8
 *
9
 
 * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
 
9
 * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
10
10
 *
11
11
 * This software is licensed as described in the file COPYING, which
12
12
 * you should have received as part of this distribution. The terms
19
19
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
20
 * KIND, either express or implied.
21
21
 *
22
 
 * $Id: memdebug.c,v 1.48 2005/06/30 13:30:23 bagder Exp $
 
22
 * $Id: memdebug.c,v 1.51 2007-02-21 19:03:20 yangtse Exp $
23
23
 ***************************************************************************/
24
24
 
25
25
#include "setup.h"
61
61
 */
62
62
 
63
63
#define logfile curl_debuglogfile
64
 
FILE *curl_debuglogfile;
65
 
static bool memlimit; /* enable memory limit */
66
 
static long memsize;  /* set number of mallocs allowed */
 
64
FILE *curl_debuglogfile = NULL;
 
65
static bool memlimit = FALSE; /* enable memory limit */
 
66
static long memsize = 0;  /* set number of mallocs allowed */
67
67
 
68
68
/* this sets the log file name */
69
69
void curl_memdebug(const char *logname)
70
70
{
71
 
  if(logname)
72
 
    logfile = fopen(logname, "w");
73
 
  else
74
 
    logfile = stderr;
 
71
  if (!logfile) {
 
72
    if(logname)
 
73
      logfile = fopen(logname, "w");
 
74
    else
 
75
      logfile = stderr;
 
76
  }
75
77
}
76
78
 
77
79
/* This function sets the number of malloc() calls that should return
78
80
   successfully! */
79
81
void curl_memlimit(long limit)
80
82
{
81
 
  memlimit = TRUE;
82
 
  memsize = limit;
 
83
  if (!memlimit) {
 
84
    memlimit = TRUE;
 
85
    memsize = limit;
 
86
  }
83
87
}
84
88
 
85
89
/* returns TRUE if this isn't allowed! */
95
99
      if(source)
96
100
        fprintf(stderr, "LIMIT %s:%d %s reached memlimit\n",
97
101
                source, line, func);
98
 
      errno = ENOMEM;
 
102
      SET_ERRNO(ENOMEM);
99
103
      return TRUE; /* RETURN ERROR! */
100
104
    }
101
105
    else
166
170
  char *mem;
167
171
  size_t len;
168
172
 
169
 
  curlassert(str != NULL);
 
173
  DEBUGASSERT(str != NULL);
170
174
 
171
175
  if(countcheck("strdup", line, source))
172
176
    return NULL;
216
220
{
217
221
  struct memdebug *mem;
218
222
 
219
 
  curlassert(ptr != NULL);
 
223
  DEBUGASSERT(ptr != NULL);
220
224
 
221
225
  mem = (struct memdebug *)((char *)ptr - offsetof(struct memdebug, mem));
222
226
 
276
280
{
277
281
  int res;
278
282
 
279
 
  curlassert(file != NULL);
 
283
  DEBUGASSERT(file != NULL);
280
284
 
281
285
  res=(fclose)(file);
282
286
  if(logfile)