- * Ensure any subsequent attempt to grab this semaphore will fail
- * with an assert, instead of just silently hanging.
- */
- memset(sem, 0, sizeof(*sem));
+ * When not running on Valgrind, ensure any subsequent attempt to grab
+ * this semaphore will fail with an assert, instead of just silently
+ * hanging. When running on Valgrind, let Valgrind detect
+ * use-after-free.
+ */
+ if (!RUNNING_ON_VALGRIND)
+ memset(sem, 0, sizeof(*sem));