#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
#include <yaz/log.h>
#include <yaz/xmalloc.h>
#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;
xmalloc_trav_d(file, line);
}
-void xmalloc_fatal(void)
+void xmalloc_fatal(size_t size)
{
+ assert(size < MALLOC_SIZE_MAX);
exit(1);
}
{
yaz_log(YLOG_FATAL|YLOG_ERRNO, "Out of memory, realloc (%ld bytes)",
(long) size);
- xmalloc_fatal();
+ xmalloc_fatal(size);
}
return p;
}
{
yaz_log(YLOG_FATAL, "Out of memory - malloc (%ld bytes)",
(long) size);
- xmalloc_fatal();
+ xmalloc_fatal(size);
}
return p;
}
{
yaz_log(YLOG_FATAL, "Out of memory - calloc (%ld, %ld)",
(long) nmemb, (long) size);
- xmalloc_fatal();
+ xmalloc_fatal(size);
}
return p;
}