mutex: add __fio_mutex_remove()

We have to remember to free the condvar, so add a __fio_mutex_remove()
for cases that init a mutex inside an smalloc'ed region with
__fio_mutex_init().

Signed-off-by: Jens Axboe <axboe@fb.com>
diff --git a/filelock.c b/filelock.c
index b252a97..18e8875 100644
--- a/filelock.c
+++ b/filelock.c
@@ -144,10 +144,11 @@
 
 	ff = fio_hash_find(hash);
 	if (ff) {
-		ff->references--;
+		int refs = --ff->references;
 		fio_mutex_up(&ff->lock);
-		if (!ff->references) {
+		if (!refs) {
 			flist_del(&ff->list);
+			__fio_mutex_remove(&ff->lock);
 			sfree(ff);
 		}
 	} else
diff --git a/mutex.c b/mutex.c
index 9ee3bd8..53f9651 100644
--- a/mutex.c
+++ b/mutex.c
@@ -18,10 +18,15 @@
 #include "fio_time.h"
 #include "gettime.h"
 
-void fio_mutex_remove(struct fio_mutex *mutex)
+void __fio_mutex_remove(struct fio_mutex *mutex)
 {
 	assert(mutex->magic == FIO_MUTEX_MAGIC);
 	pthread_cond_destroy(&mutex->cond);
+}
+
+void fio_mutex_remove(struct fio_mutex *mutex)
+{
+	__fio_mutex_remove(mutex);
 	munmap((void *) mutex, sizeof(*mutex));
 }
 
diff --git a/mutex.h b/mutex.h
index 246afee..17380de 100644
--- a/mutex.h
+++ b/mutex.h
@@ -26,6 +26,7 @@
 
 extern int __fio_mutex_init(struct fio_mutex *, int);
 extern struct fio_mutex *fio_mutex_init(int);
+extern void __fio_mutex_remove(struct fio_mutex *);
 extern void fio_mutex_remove(struct fio_mutex *);
 extern void fio_mutex_up(struct fio_mutex *);
 extern void fio_mutex_down(struct fio_mutex *);
diff --git a/server.c b/server.c
index ede291f..3171979 100644
--- a/server.c
+++ b/server.c
@@ -1431,6 +1431,7 @@
 	*datap = data;
 
 	sfree(rep->data);
+	__fio_mutex_remove(&rep->lock);
 	sfree(rep);
 	return 0;
 }