// Local functions.
+static void mutex_cleanup(struct mutex_info* p);
static Bool mutex_is_locked(struct mutex_info* const p);
static void mutex_destroy(struct mutex_info* const p);
tl_assert(p->a1 == mutex);
tl_assert(p->a2 == mutex + size);
- p->cleanup = (void(*)(DrdClientobj*))&mutex_destroy;
+ p->cleanup = (void(*)(DrdClientobj*))&mutex_cleanup;
p->mutex_type = mutex_type;
p->recursion_count = 0;
p->owner = DRD_INVALID_THREADID;
vc_init(&p->vc, 0, 0);
}
+/** Deallocate the memory that was allocated by mutex_initialize(). */
+static void mutex_cleanup(struct mutex_info* p)
+{
+ if (mutex_is_locked(p))
+ {
+ MutexErrInfo MEI = { p->a1, p->recursion_count, p->owner };
+ VG_(maybe_record_error)(VG_(get_running_tid)(),
+ MutexErr,
+ VG_(get_IP)(VG_(get_running_tid)()),
+ "Destroying locked mutex",
+ &MEI);
+ }
+
+ vc_cleanup(&p->vc);
+}
+
static
struct mutex_info*
mutex_get_or_allocate(const Addr mutex,
p->a1);
}
- if (mutex_is_locked(p))
- {
- MutexErrInfo MEI = { p->a1, p->recursion_count, p->owner };
- VG_(maybe_record_error)(VG_(get_running_tid)(),
- MutexErr,
- VG_(get_IP)(VG_(get_running_tid)()),
- "Destroying locked mutex",
- &MEI);
- }
-
drd_clientobj_remove(p->a1);
}
-void mutex_pre_destroy(struct mutex_info* const p)
-{
- return mutex_destroy(p);
-}
-
+/** Called after pthread_mutex_destroy(). */
void mutex_post_destroy(const Addr mutex)
{
struct mutex_info* p;
tl_assert(p);
if (p)
{
- if (mutex_get_recursion_count(mutex) > 0)
- {
- const ThreadId vg_tid = VG_(get_running_tid)();
- MutexErrInfo MEI = { p->a1, p->recursion_count, p->owner };
- VG_(maybe_record_error)(vg_tid,
- MutexErr,
- VG_(get_IP)(vg_tid),
- "Destroying locked mutex",
- &MEI);
- }
- mutex_pre_destroy(p);
+ mutex_destroy(p);
}
}
void mutex_set_trace(const Bool trace_mutex);
struct mutex_info* mutex_init(const Addr mutex, const SizeT size,
const MutexT mutex_type);
-void mutex_pre_destroy(struct mutex_info* const p);
void mutex_post_destroy(const Addr mutex);
struct mutex_info* mutex_get(const Addr mutex);
void mutex_pre_lock(const Addr mutex, const SizeT size, const MutexT mutex_type);
--- /dev/null
+
+Destroying locked mutex: address 0x........, recursion count 1, owner 1.
+ at 0x........: bar (tc04_free_lock.c:40)
+ by 0x........: (below main) (in /...libc...)
+
+Destroying locked mutex: address 0x........, recursion count 1, owner 1.
+ at 0x........: foo (tc04_free_lock.c:49)
+ by 0x........: (below main) (in /...libc...)
+
+Destroying locked mutex: address 0x........, recursion count 1, owner 1.
+ at 0x........: bar (tc04_free_lock.c:40)
+ by 0x........: (below main) (in /...libc...)
+
+ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 0 from 0)
---------------- pthread_mutex_lock et al ----------------
-Destroying locked mutex: address 0x........, recursion count 1, owner 1.
- at 0x........: pthread_mutex_destroy (drd_intercepts.c:?)
- by 0x........: main (tc20_verifywrap.c:102)
-
-Destroying locked mutex: address 0x........, recursion count 1, owner 1.
- at 0x........: pthread_mutex_destroy (drd_intercepts.c:?)
- by 0x........: main (tc20_verifywrap.c:102)
-
Destroying locked mutex: address 0x........, recursion count 1, owner 1.
at 0x........: pthread_mutex_destroy (drd_intercepts.c:?)
by 0x........: main (tc20_verifywrap.c:102)
Destroying locked mutex: address 0x........, recursion count 1, owner 1.
at 0x........: main (tc20_verifywrap.c:262)
-ERROR SUMMARY: 8 errors from 8 contexts (suppressed: 0 from 0)
+ERROR SUMMARY: 6 errors from 6 contexts (suppressed: 0 from 0)