Patch:Glib:Patch for internal glib, which causes maptool to segfault
authoranhanguera <anhanguera@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Fri, 1 Jul 2011 00:56:01 +0000 (00:56 +0000)
committeranhanguera <anhanguera@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Fri, 1 Jul 2011 00:56:01 +0000 (00:56 +0000)
Linux distch 2.6.38-8-generic Ubuntu-11.4 with no glib-2, glib-1 devel packages

maptool gets segfault when compiled with internal glib, valgrind output follows;

- valgrind:

tile_collector_finish
tile_collector_finish foreach done
==13022== Invalid read of size 4
==13022==    at 0x404333D: pthread_mutex_lock (pthread_mutex_lock.c:50)
==13022==    by 0x807F49A: g_atomic_int_exchange_and_add (gatomic.c:744)
==13022==    by 0x807C00C: g_hash_table_unref (ghash.c:619)
==13022==    by 0x807C3A9: g_hash_table_destroy (ghash.c:645)
==13022==    by 0x804E6B4: process_coastlines (coastline.c:510)
==13022==    by 0x804C276: main (maptool.c:486)
==13022==  Address 0xc is not stack'd, malloc'd or (recently) free'd

- cause

in gatomic, g_atomic_mutex is global static, and never gets initialized. eventualy
mutex_lock() is called with null, and gets the segfault.

alper.

git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@4559 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/support/glib/fake.h

index df6ae58..ba9b177 100644 (file)
@@ -13,9 +13,9 @@
 #if USE_POSIX_THREADS
 # define GMutex pthread_mutex_t
 # define g_mutex_new g_mutex_new_navit
-# define g_mutex_lock(lock) (pthread_mutex_lock(lock))
-# define g_mutex_unlock(lock) (pthread_mutex_unlock(lock))
-# define g_mutex_trylock(lock) (pthread_mutex_trylock(lock) == 0)
+# define g_mutex_lock(lock) ((lock == NULL) ? 0 : pthread_mutex_lock(lock))
+# define g_mutex_unlock(lock) ((lock == NULL) ? 0 : pthread_mutex_unlock(lock))
+# define g_mutex_trylock(lock) (((lock == NULL) ? 0 : pthread_mutex_trylock(lock)) == 0)
 #  define GPrivate pthread_key_t
 #  define g_private_new(xd) g_private_new_navit()
 #  define g_private_get(xd) pthread_getspecific(xd)