Index: uspace/lib/drv/generic/driver.c
===================================================================
--- uspace/lib/drv/generic/driver.c	(revision 1558d85ed379df2444da9a5e16727816dbb0a4b8)
+++ uspace/lib/drv/generic/driver.c	(revision 9fbc7fad0e2650dd52506a58a04421ffffb3fc31)
@@ -335,6 +335,7 @@
 	fibril_mutex_lock(&functions_mutex);
 	ddf_fun_t *fun = driver_get_function(handle);
+	if (fun != NULL)
+		fun_add_ref(fun);
 	fibril_mutex_unlock(&functions_mutex);
-	/* XXX Need a lock on fun */
 	
 	if (fun == NULL) {
@@ -348,4 +349,5 @@
 		/* Driver has a custom connection handler. */
 		(*fun->conn_handler)(iid, icall, (void *)fun);
+		fun_del_ref(fun);
 		return;
 	}
@@ -362,6 +364,8 @@
 	
 	async_answer_0(iid, ret);
-	if (ret != EOK)
+	if (ret != EOK) {
+		fun_del_ref(fun);
 		return;
+	}
 	
 	while (true) {
@@ -376,4 +380,5 @@
 				(*fun->ops->close)(fun);
 			async_answer_0(callid, EOK);
+			fun_del_ref(fun);
 			return;
 		}
