]> sourceware.org Git - lvm2.git/commitdiff
Trap large memory allocation requests.
authorAlasdair Kergon <agk@redhat.com>
Wed, 24 Nov 2004 21:34:56 +0000 (21:34 +0000)
committerAlasdair Kergon <agk@redhat.com>
Wed, 24 Nov 2004 21:34:56 +0000 (21:34 +0000)
WHATS_NEW
lib/Makefile.in
lib/mm/dbg_malloc.c
lib/mm/dbg_malloc.h

index 0581ab45b60173fc592af2cb0aa5c84abc565708..5dc464b374f2d836bbe522171765158269ae35d3 100644 (file)
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
 Version 2.00.27 - 24th November 2004
 ====================================
+  Trap large memory allocation requests.
   Fix to partition table detection code.
   Improve filter debug mesgs.
 
index 58041322d94f19510c20a604bd9ddc739c4ade71..4d57b736b75b93058eb0be3fa148cfa601200737 100644 (file)
@@ -76,6 +76,7 @@ SOURCES =\
        misc/crc.c \
        misc/lvm-file.c \
        misc/lvm-string.c \
+       mm/dbg_malloc.c \
        mm/memlock.c \
        mm/pool.c \
        regex/matcher.c \
@@ -121,10 +122,6 @@ ifeq ("@MIRRORS@", "internal")
   SOURCES += mirror/mirrored.c
 endif
 
-ifeq ("@DEBUG@", "yes")
-  SOURCES += mm/dbg_malloc.c
-endif
-
 ifeq ("@DEVMAPPER@", "yes")
   SOURCES +=\
        activate/dev_manager.c \
index 47cecf8c000aa497903a18356a5d2fcd3c214a4f..f0f8a6b575a6bcf8f99bc4c7e5458760aae48ff2 100644 (file)
@@ -19,6 +19,8 @@
 
 #include <stdarg.h>
 
+#ifdef DEBUG_MEM
+
 struct memblock {
        struct memblock *prev, *next;   /* All allocated blocks are linked */
        size_t length;          /* Size of the requested block */
@@ -47,7 +49,7 @@ void *malloc_aux(size_t s, const char *file, int line)
 
        if (s > 50000000) {
                log_error("Huge memory allocation (size %" PRIuPTR
-                         ") rejected - bug?", s);
+                         ") rejected - metadata corruption?", s);
                return 0;
        }
 
@@ -166,7 +168,6 @@ void *realloc_aux(void *p, unsigned int s, const char *file, int line)
        return r;
 }
 
-#ifdef DEBUG_MEM
 int dump_memory(void)
 {
        unsigned long tot = 0;
@@ -213,10 +214,18 @@ void bounds_check(void)
                mb = mb->next;
        }
 }
-#endif
 
-/*
- * Local variables:
- * c-file-style: "linux"
- * End:
- */
+#else
+
+void *malloc_aux(size_t s, const char *file, int line)
+{
+       if (s > 50000000) {
+               log_error("Huge memory allocation (size %" PRIuPTR
+                         ") rejected - metadata corruption?", s);
+               return 0;
+       }
+
+       return malloc(s);
+}
+
+#endif
index 6d6303e36c46b57c90f50b8ca625a631c2e0cd96..4d19672f385003f604ab18c59167ce0bd04c1a4f 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 
-#ifdef DEBUG_MEM
 void *malloc_aux(size_t s, const char *file, int line);
+#  define dbg_malloc(s) malloc_aux((s), __FILE__, __LINE__)
+
+#ifdef DEBUG_MEM
+
 void free_aux(void *p);
 void *realloc_aux(void *p, unsigned int s, const char *file, int line);
 int dump_memory(void);
 void bounds_check(void);
 
-#  define dbg_malloc(s) malloc_aux((s), __FILE__, __LINE__)
 #  define dbg_free(p) free_aux(p)
 #  define dbg_realloc(p, s) realloc_aux(p, s, __FILE__, __LINE__)
+
 #else
-#  define dbg_malloc(s) malloc(s)
+
 #  define dbg_free(p) free(p)
 #  define dbg_realloc(p, s) realloc(p, s)
 #  define dump_memory()
 #  define bounds_check()
+
 #endif
 
 static inline char *dbg_strdup(const char *str)
This page took 0.044863 seconds and 5 git commands to generate.