projects
/
yaz-moved-to-github.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Version 5.9.0
[yaz-moved-to-github.git]
/
src
/
xmalloc.c
diff --git
a/src/xmalloc.c
b/src/xmalloc.c
index
f3ac0b7
..
1dec219
100644
(file)
--- a/
src/xmalloc.c
+++ b/
src/xmalloc.c
@@
-14,6
+14,7
@@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
#include <yaz/log.h>
#include <yaz/xmalloc.h>
#include <yaz/log.h>
#include <yaz/xmalloc.h>
@@
-22,6
+23,9
@@
#define TRACE_XMALLOC 1
#endif
#define TRACE_XMALLOC 1
#endif
+/* treat any size >1/4 of max value of size_t to be an error */
+#define MALLOC_SIZE_MAX ((size_t)(-1) / 4)
+
static int log_level = 0;
static int log_level_initialized = 0;
static int log_level = 0;
static int log_level_initialized = 0;
@@
-244,8
+248,9
@@
void xmalloc_trav_f(const char *s, const char *file, int line)
xmalloc_trav_d(file, line);
}
xmalloc_trav_d(file, line);
}
-void xmalloc_fatal(void)
+void xmalloc_fatal(size_t size)
{
{
+ assert(size < MALLOC_SIZE_MAX);
exit(1);
}
exit(1);
}
@@
-264,9
+269,9
@@
void *xrealloc_f(void *o, size_t size, const char *file, int line)
"%s:%d: xrealloc(s=%ld) %p -> %p", file, line, (long) size, o, p);
if (!p)
{
"%s:%d: xrealloc(s=%ld) %p -> %p", file, line, (long) size, o, p);
if (!p)
{
- yaz_log(YLOG_FATAL|YLOG_ERRNO, "Out of memory, realloc (%ld bytes)",
- (long) size);
- xmalloc_fatal();
+ yaz_log(YLOG_FATAL, "%s:%d: Out of memory, realloc(%ld bytes)",
+ file, line, (long) size);
+ xmalloc_fatal(size);
}
return p;
}
}
return p;
}
@@
-287,9
+292,9
@@
void *xmalloc_f(size_t size, const char *file, int line)
if (!p)
{
if (!p)
{
- yaz_log(YLOG_FATAL, "Out of memory - malloc (%ld bytes)",
- (long) size);
- xmalloc_fatal();
+ yaz_log(YLOG_FATAL, "%s:%d: Out of memory - malloc(%ld bytes)",
+ file, line, (long) size);
+ xmalloc_fatal(size);
}
return p;
}
}
return p;
}
@@
-309,9
+314,9
@@
void *xcalloc_f(size_t nmemb, size_t size, const char *file, int line)
if (!p)
{
if (!p)
{
- yaz_log(YLOG_FATAL, "Out of memory - calloc (%ld, %ld)",
- (long) nmemb, (long) size);
- xmalloc_fatal();
+ yaz_log(YLOG_FATAL, "%s:%d: Out of memory - calloc(%ld, %ld)",
+ file, line, (long) nmemb, (long) size);
+ xmalloc_fatal(size);
}
return p;
}
}
return p;
}