Adapt malloc macro's to only display errors during init, not during runtime. At runtime it could make us crawl if the system runs out of memory.

remotes/origin/master-1.1.x
Victor Julien 15 years ago
parent 22f770f3bf
commit 25d1b6fec1

@ -145,24 +145,15 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage);
})
#else /* DBG_MEM_ALLOC */
#if 0
/* without any checks */
#define SCMalloc malloc
#define SCRealloc realloc
#define SCCalloc calloc
#define SCStrdup strdup
#define SCFree(a) free((a))
#endif
#if 0
#define SCMalloc(a) ({ \
void *ptrmem = NULL; \
\
ptrmem = malloc(a); \
if (ptrmem == NULL && a > 0) { \
SCLogError(SC_ERR_MEM_ALLOC, "SCMalloc failed: %s, while trying " \
"to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)a); \
if (ptrmem == NULL) { \
if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\
SCLogError(SC_ERR_MEM_ALLOC, "SCMalloc failed: %s, while trying " \
"to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)a); \
SCLogError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); \
exit(EXIT_FAILURE); \
} \
@ -174,10 +165,10 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage);
void *ptrmem = NULL; \
\
ptrmem = realloc(x, a); \
if (ptrmem == NULL && a > 0) { \
SCLogError(SC_ERR_MEM_ALLOC, "SCRealloc failed: %s, while trying " \
"to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)a); \
if (ptrmem == NULL) { \
if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\
SCLogError(SC_ERR_MEM_ALLOC, "SCRealloc failed: %s, while trying " \
"to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)a); \
SCLogError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); \
exit(EXIT_FAILURE); \
} \
@ -189,10 +180,10 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage);
void *ptrmem = NULL; \
\
ptrmem = calloc(nm, a); \
if (ptrmem == NULL && a > 0) { \
SCLogError(SC_ERR_MEM_ALLOC, "SCCalloc failed: %s, while trying " \
"to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)a); \
if (ptrmem == NULL) { \
if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\
SCLogError(SC_ERR_MEM_ALLOC, "SCCalloc failed: %s, while trying " \
"to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)a); \
SCLogError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); \
exit(EXIT_FAILURE); \
} \
@ -205,21 +196,16 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage);
\
ptrmem = strdup(a); \
if (ptrmem == NULL) { \
size_t len = strlen(a); \
SCLogError(SC_ERR_MEM_ALLOC, "SCStrdup failed: %s, while trying " \
"to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)len); \
if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\
size_t len = strlen(a); \
SCLogError(SC_ERR_MEM_ALLOC, "SCStrdup failed: %s, while trying " \
"to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)len); \
SCLogError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); \
exit(EXIT_FAILURE); \
} \
} \
(void*)ptrmem; \
})
#endif
#define SCMalloc malloc
#define SCRealloc realloc
#define SCCalloc calloc
#define SCStrdup strdup
#define SCFree(a) ({ \
free(a); \

Loading…
Cancel
Save