]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
util/mem: remove old debug code for counting allocs
authorVictor Julien <victor@inliniac.net>
Wed, 27 Nov 2019 17:13:32 +0000 (18:13 +0100)
committerVictor Julien <victor@inliniac.net>
Fri, 10 Apr 2020 19:06:35 +0000 (21:06 +0200)
src/runmode-unittests.c
src/suricata.c
src/util-mem.h

index 7632dbfec2752caed80647345b2aa9ef37d780e4..1cf6ba4d6cf9bc1abf2cd0aa807f224216d12e6b 100644 (file)
@@ -245,9 +245,6 @@ void RunUnittests(int list_unittests, const char *regex_arg)
 
     CIDRInit();
 
-#ifdef DBG_MEM_ALLOC
-    SCLogInfo("Memory used at startup: %"PRIdMAX, (intmax_t)global_mem);
-#endif
     SCProtoNameInit();
 
     TagInitCtx();
@@ -301,9 +298,6 @@ void RunUnittests(int list_unittests, const char *regex_arg)
 #ifdef HAVE_LUAJIT
     LuajitFreeStatesPool();
 #endif
-#ifdef DBG_MEM_ALLOC
-    SCLogInfo("Total memory used (without SCFree()): %"PRIdMAX, (intmax_t)global_mem);
-#endif
 
     exit(EXIT_SUCCESS);
 #else
index 0cc79eea5bc64e46bb904f817c8d86db9e0f7227..84e3b8340601206d64e2191fa32a23ae2c2ee91e 100644 (file)
@@ -313,20 +313,6 @@ static void SignalHandlerSigHup(/*@unused@*/ int sig)
 }
 #endif
 
-#ifdef DBG_MEM_ALLOC
-#ifndef _GLOBAL_MEM_
-#define _GLOBAL_MEM_
-/* This counter doesn't complain realloc's(), it's gives
- * an aproximation for the startup */
-size_t global_mem = 0;
-#ifdef DBG_MEM_ALLOC_SKIP_STARTUP
-uint8_t print_mem_flag = 0;
-#else
-uint8_t print_mem_flag = 1;
-#endif
-#endif
-#endif
-
 void GlobalsInitPreConfig(void)
 {
     TimeInit();
@@ -340,13 +326,6 @@ static void GlobalsDestroy(SCInstance *suri)
     HTPFreeConfig();
     HTPAtExitPrintStats();
 
-#ifdef DBG_MEM_ALLOC
-    SCLogInfo("Total memory used (without SCFree()): %"PRIdMAX, (intmax_t)global_mem);
-#ifdef DBG_MEM_ALLOC_SKIP_STARTUP
-    print_mem_flag = 0;
-#endif
-#endif
-
     AppLayerHtpPrintStats();
 
     /* TODO this can do into it's own func */
@@ -2791,13 +2770,6 @@ int SuricataMain(int argc, char **argv)
 
     PostRunStartedDetectSetup(&suricata);
 
-#ifdef DBG_MEM_ALLOC
-    SCLogInfo("Memory used at startup: %"PRIdMAX, (intmax_t)global_mem);
-#ifdef DBG_MEM_ALLOC_SKIP_STARTUP
-    print_mem_flag = 1;
-#endif
-#endif
-
     SCPledge();
     SuricataMainLoop(&suricata);
 
index 52ed35d51889adadbf04960fa5c265c490624278..8da52c34ecbbce4deb4900f99fda3bdae0e7ce43 100644 (file)
 
 SC_ATOMIC_EXTERN(unsigned int, engine_stage);
 
-/* Use this only if you want to debug memory allocation and free()
- * It will log a lot of lines more, so think that is a performance killer */
-
-/* Uncomment this if you want to print memory allocations and free's() */
-//#define DBG_MEM_ALLOC
-
-#ifdef DBG_MEM_ALLOC
-
-/* Uncomment this if you want to print mallocs at the startup (recommended) */
-#define DBG_MEM_ALLOC_SKIP_STARTUP
-
-#define SCMalloc(a) ({ \
-    void *ptrmem = NULL; \
-    extern size_t global_mem; \
-    extern uint8_t print_mem_flag; \
-    \
-    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 (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\
-            SCLogError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); \
-            exit(EXIT_FAILURE); \
-        } \
-    } \
-    \
-    global_mem += (a); \
-    if (print_mem_flag == 1) {                               \
-        SCLogInfo("SCMalloc return at %p of size %"PRIuMAX, \
-            ptrmem, (uintmax_t)(a)); \
-    }                                \
-    (void*)ptrmem; \
-})
-
-#define SCRealloc(x, a) ({ \
-    void *ptrmem = NULL; \
-    extern size_t global_mem; \
-    extern uint8_t print_mem_flag; \
-    \
-    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 (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\
-            SCLogError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); \
-            exit(EXIT_FAILURE); \
-        } \
-    } \
-    \
-    global_mem += (a); \
-    if (print_mem_flag == 1) {                                         \
-        SCLogInfo("SCRealloc return at %p (old:%p) of size %"PRIuMAX, \
-            ptrmem, (x), (uintmax_t)(a)); \
-    }                                     \
-    (void*)ptrmem; \
-})
-
-#define SCCalloc(nm, a) ({ \
-    void *ptrmem = NULL; \
-    extern size_t global_mem; \
-    extern uint8_t print_mem_flag; \
-    \
-    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 (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\
-            SCLogError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); \
-            exit(EXIT_FAILURE); \
-        } \
-    } \
-    \
-    global_mem += (a)*(nm); \
-    if (print_mem_flag == 1) {                                          \
-        SCLogInfo("SCCalloc return at %p of size %"PRIuMAX" (nm) %"PRIuMAX, \
-            ptrmem, (uintmax_t)(a), (uintmax_t)(nm)); \
-    }                                                 \
-    (void*)ptrmem; \
-})
-
-#define SCStrdup(a) ({ \
-    char *ptrmem = NULL; \
-    extern size_t global_mem; \
-    extern uint8_t print_mem_flag; \
-    size_t _len = strlen((a)); \
-    \
-    ptrmem = strdup((a)); \
-    if (ptrmem == NULL) { \
-        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) {\
-            SCLogError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); \
-            exit(EXIT_FAILURE); \
-        } \
-    } \
-    \
-    global_mem += _len; \
-    if (print_mem_flag == 1) {                              \
-        SCLogInfo("SCStrdup return at %p of size %"PRIuMAX, \
-            ptrmem, (uintmax_t)_len);                       \
-    }                                \
-    (void*)ptrmem; \
-})
-
-#ifndef HAVE_STRNDUP
-#define SCStrndup(a, b) ({ \
-    char *ptrmem = NULL; \
-    extern size_t global_mem; \
-    extern uint8_t print_mem_flag; \
-    size_t _len = (b); \
-    \
-    size_t _scstrndup_len = _len + 1; \
-    ptrmem = (char *)malloc(_scstrndup_len); \
-    if (ptrmem == NULL) { \
-        SCLogError(SC_ERR_MEM_ALLOC, "SCStrndup failed: %s, while trying " \
-            "to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)_scstrndup_len); \
-        if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\
-            SCLogError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); \
-            exit(EXIT_FAILURE); \
-        } \
-    } else { \
-        strlcpy(ptrmem, (a), _scstrndup_len); \
-        *(ptrmem + _len) = '\0'; \
-    } \
-    \
-    global_mem += _scstrndup_len; \
-    if (print_mem_flag == 1) {                              \
-        SCLogInfo("SCStrndup return at %p of size %"PRIuMAX, \
-            ptrmem, (uintmax_t)_scstrndup_len); \
-    }                                \
-    (void*)ptrmem; \
-})
-#else /* HAVE_STRNDUP */
-#define SCStrndup(a, b) ({ \
-    char *ptrmem = NULL; \
-    extern size_t global_mem; \
-    extern uint8_t print_mem_flag; \
-    size_t _len = (b); \
-    \
-    ptrmem = strndup((a), _len); \
-    if (ptrmem == NULL) { \
-        SCLogError(SC_ERR_MEM_ALLOC, "SCStrndup failed: %s, while trying " \
-            "to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)_len); \
-        if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\
-            SCLogError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); \
-            exit(EXIT_FAILURE); \
-        } \
-    } \
-    \
-    global_mem += _len; \
-    if (print_mem_flag == 1) {                              \
-        SCLogInfo("SCStrndup return at %p of size %"PRIuMAX, \
-            ptrmem, (uintmax_t)_len); \
-    }                                \
-    (void*)ptrmem; \
-})
-#endif
-
-#define SCFree(a) ({ \
-    extern uint8_t print_mem_flag; \
-    if (print_mem_flag == 1) {          \
-        SCLogInfo("SCFree at %p", (a)); \
-    }                                   \
-    free((a)); \
-})
-
-#else /* !DBG_MEM_ALLOC */
-
 #define SCMalloc(a) ({ \
     void *ptrmem = NULL; \
     \
@@ -391,8 +223,6 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage);
 
 #endif /* __WIN32 */
 
-#endif /* DBG_MEM_ALLOC */
-
 #endif /* CPPCHECK */
 
 #endif /* __UTIL_MEM_H__ */