Don't call memset() before checking that the ptr is not NULL.
diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h
index a415a43..781467f 100644
--- a/Python/thread_pthread.h
+++ b/Python/thread_pthread.h
@@ -355,8 +355,8 @@
 		PyThread_init_thread();
 
 	lock = (pthread_lock *) malloc(sizeof(pthread_lock));
-	memset((void *)lock, '\0', sizeof(pthread_lock));
 	if (lock) {
+		memset((void *)lock, '\0', sizeof(pthread_lock));
 		lock->locked = 0;
 
 		status = pthread_mutex_init(&lock->mut,