Package: electric-fence
Version: 2.1.14.1
Severity: important
Tags: patch

Hello,

The pthread support is currently completely bogus (using getpid() to
identify threads has been bogus since Linux 2.6...). I don't know why
patch 365382 has still not been included, I guess that's because it's
quite intrusive. The attached patch is much less intrusive and should
thus be fine to be applied ASAP.

Thanks,
Samuel

-- System Information:
Debian Release: squeeze/sid
  APT prefers testing
  APT policy: (990, 'testing'), (500, 'unstable'), (500, 'stable'), (1, 
'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.30 (SMP w/2 CPU cores)
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages electric-fence depends on:
ii  libc6                         2.9-23     GNU C Library: Shared libraries

electric-fence recommends no packages.

electric-fence suggests no packages.

-- no debconf information

-- 
Samuel Thibault <[email protected]>
<s> bah, j'aime bien les feux d'artifices, mais j'ai peur de me prendre un 
boeing sur le coin de la gueule si je vais sur le pont de brooklyn
 -+- #ens-mim - 11 septembre forever -+-
--- electric-fence-2.1.14.1.original/efence.c   2005-01-15 20:18:20.000000000 
+0100
+++ electric-fence-2.1.14.1/efence.c    2009-08-13 22:27:43.000000000 +0200
@@ -188,28 +188,28 @@
  /*
  * mutex to enable multithreaded operation
  */
-static pthread_mutex_t mutex ;
-static pid_t mutexpid=0;
+static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_t mutexowner = (pthread_t) -1;
 static int locknr=0;
 
 
 static void lock() {
     if (pthread_mutex_trylock(&mutex)) {
-       if (mutexpid==getpid()) {
+       if (mutexowner==pthread_self()) {
            locknr++;
            return;
        } else {
            pthread_mutex_lock(&mutex);
        }
     } 
-    mutexpid=getpid();
+    mutexowner=pthread_self();
     locknr=1;
 }
 
 static void unlock() {
     locknr--;
     if (!locknr) {
-       mutexpid=0;
+       mutexowner=(pthread_t)-1;
        pthread_mutex_unlock(&mutex);
     }
 }
@@ -429,6 +429,8 @@
        size_t          slack;
        char *          address;
 
+       lock();
+
        if ( allocationList == 0 )
                initialize();
 
@@ -615,6 +617,7 @@
        if ( !internalUse )
                Page_DenyAccess(allocationList, allocationListSize);
 
+       unlock();
        return address;
 }
 
@@ -814,11 +817,9 @@
 {
         void  *allocation;   
  
-        if ( allocationList == 0 ) {
-                pthread_mutex_init(&mutex, NULL); 
-                initialize();   /* This sets EF_ALIGNMENT */
-        }       
         lock();
+        if ( allocationList == 0 )
+                initialize();   /* This sets EF_ALIGNMENT */
         allocation=memalign(EF_ALIGNMENT, size); 
 
         unlock();
@@ -833,10 +834,9 @@
         void * allocation;
         
         lock();
-       
         allocation = malloc(size);
-        memset(allocation, 0, size);
         unlock();
+        memset(allocation, 0, size);
 
        return allocation;
 }

Reply via email to