loader: correct compiler warning

Fixed compiler warning of idx potentially being
undefined. Also added test to check if the code
took that path and return an error if that happens.
diff --git a/loader/loader.c b/loader/loader.c
index 3f71cde..4a83b49 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -2578,7 +2578,7 @@
         struct loader_instance *inst,
         struct loader_layer_properties *layer_prop)
 {
-    uint32_t idx;
+    uint32_t idx = loader.loaded_layer_lib_count;
     struct loader_lib_info *new_layer_lib_list, *my_lib = NULL;
 
     for (uint32_t i = 0; i < loader.loaded_layer_lib_count; i++) {
@@ -2590,6 +2590,12 @@
         }
     }
 
+    if (idx == loader.loaded_layer_lib_count) {
+        loader_log(VK_DEBUG_REPORT_ERROR_BIT, 0,
+                   "Unable to unref library %s", layer_prop->lib_name);
+        return;
+    }
+
     if (my_lib) {
         my_lib->ref_count--;
         if (my_lib->ref_count > 0) {