Hi,
For those who like I are stuck with log4cxx v0.9.7 and have experienced memory 
leaks and crashes in x86_64 (64bit) builds on Linux,
Here is a small fix:

(Base is 0.9.7)
src\thread.cpp:

@@ -201,6 +201,14 @@
                              : "0" (1), "m" (*val));
 
        return ret+1;
+#elif defined(__x86_64__)
+       long ret;
+       
+       __asm__ __volatile__ ("lock; xadd %0, %1"
+                             : "=r" (ret), "=m" (*val)
+                             : "0" (1), "m" (*val));
+
+       return ret+1;
 #elif defined(sparc) && defined(__SUNPRO_CC)
        sparc_atomic_add_32(val, 1);
        return *val;
@@ -226,6 +234,14 @@
                              : "0" (-1), "m" (*val));
 
        return ret-1;
+#elif defined(__x86_64__)
+       long ret;
+
+       __asm__ __volatile__ ("lock; xadd %0, %1"
+                             : "=r" (ret), "=m" (*val)
+                             : "0" (-1), "m" (*val));
+
+       return ret-1;
        
 #elif defined(sparc) && defined(__SUNPRO_CC)
        sparc_atomic_add_32(val, -1);


The problem was that the locked increment/decrement functions (used by the 
reference counting for smart pointers for all of log4cxx's dynamic objects) had 
empty function bodies on x86_64 systems.
Note: The latest 0.10.x versions probably don't have this issue as they are 
relying on Apache libs for locked increment.

hope it can be usefull,
Best regards,
Lars Ruoff

Reply via email to