From 22f770f3bfc713eeb20229115ac0bf8e2f4fc677 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Tue, 6 Jul 2010 11:58:05 +0200 Subject: [PATCH] Better handle low memory conditions. --- src/util-debug.c | 8 ++++---- src/util-mem.h | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/util-debug.c b/src/util-debug.c index 47723e690b..515a607f63 100644 --- a/src/util-debug.c +++ b/src/util-debug.c @@ -943,10 +943,10 @@ SCLogInitData *SCLogAllocLogInitData(void) { SCLogInitData *sc_lid = NULL; - if ( (sc_lid = malloc(sizeof(SCLogInitData))) == NULL) { - SCLogError(SC_ERR_FATAL, "Fatal error encountered initializing the logging subsytem. Out of memory. Exiting..."); - exit(EXIT_FAILURE); - } + /* not using SCMalloc here because if it fails we can't log */ + if ( (sc_lid = malloc(sizeof(SCLogInitData))) == NULL) + return NULL; + memset(sc_lid, 0, sizeof(SCLogInitData)); return sc_lid; diff --git a/src/util-mem.h b/src/util-mem.h index 4adcd8abc0..1ba9e07538 100644 --- a/src/util-mem.h +++ b/src/util-mem.h @@ -154,6 +154,7 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage); #define SCFree(a) free((a)) #endif +#if 0 #define SCMalloc(a) ({ \ void *ptrmem = NULL; \ \ @@ -214,6 +215,11 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage); } \ (void*)ptrmem; \ }) +#endif +#define SCMalloc malloc +#define SCRealloc realloc +#define SCCalloc calloc +#define SCStrdup strdup #define SCFree(a) ({ \ free(a); \