On 9/2/07, Jim Meyering <[EMAIL PROTECTED]> wrote:
> I like removing all of the ifdef'd-out cruft, but not the change
> that sets MALLOC_CHECK_ in the environment.
> MALLOC_CHECK_ is system specific, and besides, libraries (even when
> compiled in debug mode) shouldn't be setting environment variables.
I have reverted that commit with another that only removes the ifdef'd
malloc debugging code.

Regards,
Frodo B
>From 79ecd16daf6509dd6fde7ccc052135e3aaa96840 Mon Sep 17 00:00:00 2001
From: Frodo Baggins <[EMAIL PROTECTED]>
Date: Tue, 4 Sep 2007 17:57:01 +0530
Subject: [PATCH] Revert "add malloc debugging using MALLOC_CHECK_"

This reverts commit 9beec03970ed9b4877b67e93a48eaf1e09b1ac9e.
Will submit a separate patch removing the ifdef'd malloc debugging code.
---
 libparted/libparted.c |   73 ++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 66 insertions(+), 7 deletions(-)

diff --git a/libparted/libparted.c b/libparted/libparted.c
index 2c2c846..a8c7f0a 100644
--- a/libparted/libparted.c
+++ b/libparted/libparted.c
@@ -51,14 +51,25 @@ typedef struct
     size_t     size;
 } pointer_size_type;

+/* IMHO, none of the DEBUG-related code below is useful, and the
+   ped_malloc memset code is actually quite harmful: it masked at
+   least two nasty bugs that were fixed in June of 2007.  */
+#undef DEBUG
 #ifdef DEBUG
-/* Set MALLOC_CHECK_ to 2 so that heap corruption causes a call to abort() */
-if(NULL==getenv("MALLOC_CHECK_")){
-    if(-1==setenv("MALLOC_CHECK_","2",1)){
-       /* signal error setting this env variable */
-       fprintf(stderr,"Could not set MALLOC_CHECK_ value to 2\n");
-    }
-}
+static pointer_size_type dodgy_malloc_list[] = {
+ {0,           0},
+ {0,           0},
+ {0,           0},
+ {0,           0},
+ {0,           0},
+ {0,           0},
+ {0,           0},
+ {0,           0},
+ {0,           0},
+ {0,           0}
+};
+
+static int     dodgy_memory_active[100];
 #endif /* DEBUG */

 int
@@ -188,6 +199,9 @@ _init()
        ped_set_architecture (&ped_gnu_arch);
 #endif

+#ifdef DEBUG
+       memset (dodgy_memory_active, 0, sizeof (dodgy_memory_active));
+#endif
 }

 #ifdef ENABLE_FS
@@ -238,6 +252,42 @@ ped_get_version ()
        return VERSION;
 }

+#ifdef DEBUG
+static void
+_check_dodgy_pointer (const void* ptr, size_t size, int is_malloc)
+{
+       int             i;
+
+       for (i=0; dodgy_malloc_list[i].pointer; i++) {
+               if (dodgy_malloc_list[i].pointer != ptr)
+                       continue;
+               if (is_malloc && dodgy_malloc_list[i].size != size)
+                       continue;
+               if (!is_malloc && !dodgy_memory_active[i])
+                       continue;
+
+
+               if (is_malloc) {
+                       ped_exception_throw (
+                               PED_EXCEPTION_INFORMATION,
+                               PED_EXCEPTION_OK,
+                               "Dodgy malloc(%x) == %p occurred (active==%d)",
+                               size, ptr, dodgy_memory_active[i]);
+                       dodgy_memory_active[i]++;
+               } else {
+                       ped_exception_throw (
+                               PED_EXCEPTION_INFORMATION,
+                               PED_EXCEPTION_OK,
+                               "Dodgy free(%p) occurred (active==%d)",
+                               ptr, dodgy_memory_active[i]);
+                       dodgy_memory_active[i]--;
+               }
+
+               return;
+       }
+}
+#endif /* DEBUG */
+
 void*
 ped_malloc (size_t size)
 {
@@ -250,6 +300,11 @@ ped_malloc (size_t size)
                return NULL;
        }

+#ifdef DEBUG
+       memset (mem, 0xff, size);
+       _check_dodgy_pointer (mem, size, 1);
+#endif
+
        return mem;
 }

@@ -282,5 +337,9 @@ void* ped_calloc (size_t size)
 void
 ped_free (void* ptr)
 {
+#ifdef DEBUG
+       _check_dodgy_pointer (ptr, 0, 0);
+#endif
+
        free (ptr);
 }
--
1.4.3.4

>From 5835ff6d6f5958822143247ab33509e2f3435002 Mon Sep 17 00:00:00 2001
From: Frodo Baggins <[EMAIL PROTECTED]>
Date: Tue, 4 Sep 2007 18:02:05 +0530
Subject: [PATCH] Remove unused malloc debugging code

---
 libparted/libparted.c |   70 -------------------------------------------------
 1 files changed, 0 insertions(+), 70 deletions(-)

diff --git a/libparted/libparted.c b/libparted/libparted.c
index a8c7f0a..8b0fb5a 100644
--- a/libparted/libparted.c
+++ b/libparted/libparted.c
@@ -51,27 +51,6 @@ typedef struct
     size_t     size;
 } pointer_size_type;

-/* IMHO, none of the DEBUG-related code below is useful, and the
-   ped_malloc memset code is actually quite harmful: it masked at
-   least two nasty bugs that were fixed in June of 2007.  */
-#undef DEBUG
-#ifdef DEBUG
-static pointer_size_type dodgy_malloc_list[] = {
- {0,           0},
- {0,           0},
- {0,           0},
- {0,           0},
- {0,           0},
- {0,           0},
- {0,           0},
- {0,           0},
- {0,           0},
- {0,           0}
-};
-
-static int     dodgy_memory_active[100];
-#endif /* DEBUG */
-
 int
 ped_set_architecture (const PedArchitecture* arch)
 {
@@ -199,9 +178,6 @@ _init()
        ped_set_architecture (&ped_gnu_arch);
 #endif

-#ifdef DEBUG
-       memset (dodgy_memory_active, 0, sizeof (dodgy_memory_active));
-#endif
 }

 #ifdef ENABLE_FS
@@ -252,42 +228,6 @@ ped_get_version ()
        return VERSION;
 }

-#ifdef DEBUG
-static void
-_check_dodgy_pointer (const void* ptr, size_t size, int is_malloc)
-{
-       int             i;
-
-       for (i=0; dodgy_malloc_list[i].pointer; i++) {
-               if (dodgy_malloc_list[i].pointer != ptr)
-                       continue;
-               if (is_malloc && dodgy_malloc_list[i].size != size)
-                       continue;
-               if (!is_malloc && !dodgy_memory_active[i])
-                       continue;
-
-
-               if (is_malloc) {
-                       ped_exception_throw (
-                               PED_EXCEPTION_INFORMATION,
-                               PED_EXCEPTION_OK,
-                               "Dodgy malloc(%x) == %p occurred (active==%d)",
-                               size, ptr, dodgy_memory_active[i]);
-                       dodgy_memory_active[i]++;
-               } else {
-                       ped_exception_throw (
-                               PED_EXCEPTION_INFORMATION,
-                               PED_EXCEPTION_OK,
-                               "Dodgy free(%p) occurred (active==%d)",
-                               ptr, dodgy_memory_active[i]);
-                       dodgy_memory_active[i]--;
-               }
-
-               return;
-       }
-}
-#endif /* DEBUG */
-
 void*
 ped_malloc (size_t size)
 {
@@ -299,12 +239,6 @@ ped_malloc (size_t size)
                                     _("Out of memory."));
                return NULL;
        }
-
-#ifdef DEBUG
-       memset (mem, 0xff, size);
-       _check_dodgy_pointer (mem, size, 1);
-#endif
-
        return mem;
 }

@@ -337,9 +271,5 @@ void* ped_calloc (size_t size)
 void
 ped_free (void* ptr)
 {
-#ifdef DEBUG
-       _check_dodgy_pointer (ptr, 0, 0);
-#endif
-
        free (ptr);
 }
--
1.4.3.4

_______________________________________________
parted-devel mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/parted-devel

Reply via email to