Index: uspace/lib/c/generic/dlfcn.c
===================================================================
--- uspace/lib/c/generic/dlfcn.c	(revision aeeaf0f6c1793aa25aae1f2db6ebef814994f19d)
+++ uspace/lib/c/generic/dlfcn.c	(revision 967e7a1ea1088eaa031c0b526bf3c1963f77a1bc)
@@ -35,4 +35,5 @@
  */
 
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -53,5 +54,8 @@
 	if (m == NULL) {
 		m = module_load(runtime_env, path, mlf_local);
-		module_load_deps(m, mlf_local);
+		if (module_load_deps(m, mlf_local) != EOK) {
+			return NULL;
+		}
+
 		/* Now relocate. */
 		module_process_relocs(m);
Index: uspace/lib/c/generic/rtld/module.c
===================================================================
--- uspace/lib/c/generic/rtld/module.c	(revision aeeaf0f6c1793aa25aae1f2db6ebef814994f19d)
+++ uspace/lib/c/generic/rtld/module.c	(revision 967e7a1ea1088eaa031c0b526bf3c1963f77a1bc)
@@ -187,5 +187,5 @@
 	if (m == NULL) {
 		printf("malloc failed\n");
-		exit(1);
+		goto error;
 	}
 
@@ -198,5 +198,5 @@
 	if (str_size(name) > NAME_BUF_SIZE - 2) {
 		printf("soname too long. increase NAME_BUF_SIZE\n");
-		exit(1);
+		goto error;
 	}
 
@@ -210,5 +210,5 @@
 	if (rc != EE_OK) {
 		printf("Failed to load '%s'\n", name_buf);
-		exit(1);
+		goto error;
 	}
 
@@ -220,5 +220,5 @@
 		printf("Error: '%s' is not a dynamically-linked object.\n",
 		    name_buf);
-		exit(1);
+		goto error;
 	}
 
@@ -243,9 +243,15 @@
 
 	return m;
+
+error:
+	if (m)
+		free(m);
+
+	return NULL;
 }
 
 /** Load all modules on which m (transitively) depends.
  */
-void module_load_deps(module_t *m, mlflags_t flags)
+errno_t module_load_deps(module_t *m, mlflags_t flags)
 {
 	elf_dyn_t *dp;
@@ -274,5 +280,5 @@
 		/* There are no dependencies, so we are done. */
 		m->deps = NULL;
-		return;
+		return EOK;
 	}
 
@@ -280,5 +286,5 @@
 	if (!m->deps) {
 		printf("malloc failed\n");
-		exit(1);
+		return ENOMEM;
 	}
 
@@ -294,5 +300,8 @@
 			if (!dm) {
 				dm = module_load(m->rtld, dep_name, flags);
-				module_load_deps(dm, flags);
+				errno_t rc = module_load_deps(dm, flags);
+				if (rc != EOK) {
+					return rc;
+				}
 			}
 
@@ -302,4 +311,6 @@
 		++dp;
 	}
+
+	return EOK;
 }
 
Index: uspace/lib/c/generic/rtld/rtld.c
===================================================================
--- uspace/lib/c/generic/rtld/rtld.c	(revision aeeaf0f6c1793aa25aae1f2db6ebef814994f19d)
+++ uspace/lib/c/generic/rtld/rtld.c	(revision 967e7a1ea1088eaa031c0b526bf3c1963f77a1bc)
@@ -125,5 +125,8 @@
 
 	DPRINTF("Load all program dependencies\n");
-	module_load_deps(prog, 0);
+	errno_t rc = module_load_deps(prog, 0);
+	if (rc != EOK) {
+		return rc;
+	}
 
 	/* Compute static TLS size */
Index: uspace/lib/c/include/rtld/module.h
===================================================================
--- uspace/lib/c/include/rtld/module.h	(revision aeeaf0f6c1793aa25aae1f2db6ebef814994f19d)
+++ uspace/lib/c/include/rtld/module.h	(revision 967e7a1ea1088eaa031c0b526bf3c1963f77a1bc)
@@ -45,5 +45,5 @@
 extern module_t *module_find(rtld_t *, const char *);
 extern module_t *module_load(rtld_t *, const char *, mlflags_t);
-extern void module_load_deps(module_t *, mlflags_t);
+extern errno_t module_load_deps(module_t *, mlflags_t);
 extern module_t *module_by_id(rtld_t *, unsigned long);
 
