about summary refs log tree commit diff stats
path: root/src/librarian
diff options
context:
space:
mode:
Diffstat (limited to 'src/librarian')
-rw-r--r--src/librarian/librarian.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/librarian/librarian.c b/src/librarian/librarian.c
index 9b5e82ac..4aff1864 100644
--- a/src/librarian/librarian.c
+++ b/src/librarian/librarian.c
@@ -333,9 +333,16 @@ int AddNeededLib(lib_t* maplib, int local, int bindnow, int deepbind, needed_lib
     for (int i=0; i<n; ++i)
         if(AddNeededLib_init(maplib, local, bindnow, deepbind, needed->libs[n-i-1], verneeded, box64, emu)) {
             printf_log(LOG_INFO, "Error initializing needed lib %s\n", needed->names[i]);
-            if(!allow_missing_libs) ret = 1;
+            ret = 1;
         }
     // error while loadind lib, unload...
+    if(ret) {
+        int n = needed->size;
+        for (int i=0; i<n; ++i)
+            DecRefCount(&needed->libs[n-i-1], emu);
+    }
+    // all done
+    if(allow_missing_libs) return 0;
     return ret;
 }
 EXPORTDYN