|
From: Marcin S. <mar...@in...> - 2016-02-17 13:03:16
|
Detect pthread_mutex_init on initialized pthread_rwlock_t and
pthread_rwlock_init on initialized pthread_mutex_t as soon as possible.
Currently they are detected in _destroy and _lock, but it's a bit too
late - the problem is on initialization side.
I had hit this case in the below scenario:
struct A { pthread_mutex_t mutex; ... };
struct B { pthread_rwlock_t rwlock; ... };
struct A *a = allocA();
pthread_mutex_init(a->mutex);
// forgot pthread_mutex_destroy(&a->mutex);
freeA(a);
struct B *b = allocB(); // got exactly the same address as "a" (from non-standard allocator)
pthread_rwlock_init(&b->rwlock);
---
helgrind/hg_main.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git helgrind/hg_main.c helgrind/hg_main.c
index 3c1f12c..1b65db6 100644
--- helgrind/hg_main.c
+++ helgrind/hg_main.c
@@ -2006,8 +2006,14 @@ void evh__HG_PTHREAD_MUTEX_INIT_POST( ThreadId tid,
VG_(printf)("evh__hg_PTHREAD_MUTEX_INIT_POST(ctid=%d, mbRec=%ld, %p)\n",
(Int)tid, mbRec, (void*)mutex );
tl_assert(mbRec == 0 || mbRec == 1);
- map_locks_lookup_or_create( mbRec ? LK_mbRec : LK_nonRec,
+ Lock *lk = map_locks_lookup_or_create( mbRec ? LK_mbRec : LK_nonRec,
(Addr)mutex, tid );
+ if (lk && lk->kind == LK_rdwr) {
+ Thread* thr = map_threads_maybe_lookup( tid );
+ HG_(record_error_Misc)(thr, "pthread_mutex_init on alive rwlock "
+ "(missing pthread_rwlock_destroy before free?)");
+ }
+
if (HG_(clo_sanity_flags) & SCE_LOCKS)
all__sanity_check("evh__hg_PTHREAD_MUTEX_INIT_POST");
}
@@ -2577,7 +2583,13 @@ void evh__HG_PTHREAD_RWLOCK_INIT_POST( ThreadId tid, void* rwl )
if (SHOW_EVENTS >= 1)
VG_(printf)("evh__hg_PTHREAD_RWLOCK_INIT_POST(ctid=%d, %p)\n",
(Int)tid, (void*)rwl );
- map_locks_lookup_or_create( LK_rdwr, (Addr)rwl, tid );
+ Lock* lk = map_locks_lookup_or_create( LK_rdwr, (Addr)rwl, tid );
+ if (lk && lk->kind != LK_rdwr) {
+ Thread* thr = map_threads_maybe_lookup( tid );
+ HG_(record_error_Misc)(thr, "pthread_rwlock_init on alive mutex "
+ "(missing pthread_mutex_destroy before free?)" );
+ }
+
if (HG_(clo_sanity_flags) & SCE_LOCKS)
all__sanity_check("evh__hg_PTHREAD_RWLOCK_INIT_POST");
}
--
--------------------------------------------------------------------
Intel Technology Poland sp. z o.o.
ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN.
Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek
przegladanie lub rozpowszechnianie jest zabronione.
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by
others is strictly prohibited.
|