]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - compat/xalloc.cc
Source Format Enforcement (#1234)
[thirdparty/squid.git] / compat / xalloc.cc
index 3f3a9ae13dd7fdba5e3b1fb0ee1c50e0e7998857..812c5e3193995706c4624bc29d2f82a964402e49 100644 (file)
@@ -1,6 +1,13 @@
+/*
+ * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
 #include "squid.h"
 #include "compat/xalloc.h"
-#include "profiler/Profiler.h"
 
 #if XMALLOC_STATISTICS
 #define XMS_DBG_MAXSIZE   (1024*1024)
@@ -63,22 +70,18 @@ malloc_statistics(void (*func) (int, int, int, void *), void *data)
 void *
 xcalloc(size_t n, size_t sz)
 {
-    PROF_start(xcalloc);
-
     if (n < 1)
         n = 1;
 
     if (sz < 1)
         sz = 1;
 
-    PROF_start(calloc);
     void *p = calloc(n, sz);
-    PROF_stop(calloc);
 
-    if (p == NULL) {
+    if (!p) {
         if (failure_notify) {
             static char msg[128];
-            snprintf(msg, 128, "xcalloc: Unable to allocate %lu blocks of %lu bytes!\n", (unsigned long)n, (unsigned long)sz);
+            snprintf(msg, 128, "xcalloc: Unable to allocate %" PRIuSIZE " blocks of %" PRIuSIZE " bytes!\n", n, sz);
             failure_notify(msg);
         } else {
             perror("xcalloc");
@@ -86,40 +89,25 @@ xcalloc(size_t n, size_t sz)
         exit(1);
     }
 
-#if XMALLOC_DEBUG
-    check_malloc(p, sz * n);
-#endif
 #if XMALLOC_STATISTICS
     malloc_stat(sz * n);
 #endif
-#if XMALLOC_TRACE
-    xmalloc_show_trace(p, 1);
-#endif
-#if MEM_GEN_TRACE
-    if (tracefp)
-        fprintf(tracefp, "c:%u:%u:%p\n", (unsigned int) n, (unsigned int) sz, p);
-#endif
 
-    PROF_stop(xcalloc);
     return p;
 }
 
 void *
 xmalloc(size_t sz)
 {
-    PROF_start(xmalloc);
-
     if (sz < 1)
         sz = 1;
 
-    PROF_start(malloc);
     void *p = malloc(sz);
-    PROF_stop(malloc);
 
-    if (p == NULL) {
+    if (!p) {
         if (failure_notify) {
             static char msg[128];
-            snprintf(msg, 128, "xmalloc: Unable to allocate %lu bytes!\n", (unsigned long)sz);
+            snprintf(msg, 128, "xmalloc: Unable to allocate %" PRIuSIZE " bytes!\n", sz);
             failure_notify(msg);
         } else {
             perror("malloc");
@@ -127,47 +115,25 @@ xmalloc(size_t sz)
         exit(1);
     }
 
-#if XMALLOC_DEBUG
-    check_malloc(p, sz);
-#endif
 #if XMALLOC_STATISTICS
     malloc_stat(sz);
 #endif
-#if XMALLOC_TRACE
-    xmalloc_show_trace(p, 1);
-#endif
-#if MEM_GEN_TRACE
-    if (tracefp)
-        fprintf(tracefp, "m:%d:%p\n", sz, p);
-#endif
 
-    PROF_stop(xmalloc);
     return (p);
 }
 
 void *
 xrealloc(void *s, size_t sz)
 {
-    PROF_start(xrealloc);
-#if XMALLOC_TRACE
-    xmalloc_show_trace(s, -1);
-#endif
-
     if (sz < 1)
         sz = 1;
 
-#if XMALLOC_DEBUG
-    if (s != NULL)
-        check_free(s);
-#endif
-    PROF_start(realloc);
     void *p= realloc(s, sz);
-    PROF_stop(realloc);
 
-    if (p == NULL) {
+    if (!p) {
         if (failure_notify) {
             static char msg[128];
-            snprintf(msg, 128, "xrealloc: Unable to reallocate %lu bytes!\n", (unsigned long)sz);
+            snprintf(msg, 128, "xrealloc: Unable to reallocate %" PRIuSIZE " bytes!\n", sz);
             failure_notify(msg);
         } else {
             perror("realloc");
@@ -176,20 +142,10 @@ xrealloc(void *s, size_t sz)
         exit(1);
     }
 
-#if XMALLOC_DEBUG
-    check_malloc(p, sz);
-#endif
 #if XMALLOC_STATISTICS
     malloc_stat(sz);
 #endif
-#if XMALLOC_TRACE
-    xmalloc_show_trace(p, 1);
-#endif
-#if MEM_GEN_TRACE
-    if (tracefp)                /* new ptr, old ptr, new size */
-        fprintf(tracefp, "r:%p:%p:%d\n", p, s, sz);
-#endif
-    PROF_stop(xrealloc);
+
     return (p);
 }
 
@@ -198,22 +154,6 @@ free_const(const void *s_const)
 {
     void *s = const_cast<void *>(s_const);
 
-    PROF_start(free_const);
-#if XMALLOC_TRACE
-    xmalloc_show_trace(s, -1);
-#endif
-
-#if XMALLOC_DEBUG
-    check_free(s);
-#endif
-
-    PROF_start(free);
     free(s);
-    PROF_stop(free);
-
-#if MEM_GEN_TRACE
-    if (tracefp)
-        fprintf(tracefp, "f:%p\n", s);
-#endif
-    PROF_stop(free_const);
 }
+