4 * emalloc - return new memory obtained from the system. Belch if none.
7 #include "ntp_malloc.h"
8 #include "ntp_syslog.h"
9 #include "ntp_stdlib.h"
11 extern char *progname
;
13 #if !defined(_MSC_VER) || !defined(_DEBUG)
24 mem
= realloc(prev
, size
? size
: 1);
28 "fatal out of memory (%u bytes)", (u_int
)size
);
30 "%s: fatal out of memory (%u bytes)", progname
,
44 return erealloc(NULL
, size
);
59 "fatal out of memory duplicating %u bytes",
60 (u_int
)strlen(str
) + 1);
62 "%s: fatal out of memory duplicating %u bytes",
63 progname
, (u_int
)strlen(str
) + 1);
70 #else /* below is _MSC_VER && _DEBUG */
73 * When using the debug MS CRT allocator, each allocation stores the
74 * callsite __FILE__ and __LINE__, which is then displayed at process
75 * termination, to track down leaks. We don't want all of our
76 * allocations to show up as coming from emalloc.c, so we preserve the
77 * original callsite's source file and line using macros which pass
78 * __FILE__ and __LINE__ as parameters to these routines.
85 const char * file
, /* __FILE__ */
86 int line
/* __LINE__ */
91 mem
= _realloc_dbg(prev
, size
? size
: 1,
92 _NORMAL_BLOCK
, file
, line
);
96 "fatal: out of memory in %s line %d size %u",
97 file
, line
, (u_int
)size
);
99 "%s: fatal: out of memory in %s line %d size %u",
100 progname
, file
, line
, (u_int
)size
);
110 const char * file
, /* __FILE__ */
111 int line
/* __LINE__ */
117 bytes
= strlen(str
) + 1;
118 copy
= debug_erealloc(NULL
, bytes
, file
, line
);
119 memcpy(copy
, str
, bytes
);
124 #endif /* _MSC_VER && _DEBUG */