loader: make the instance dispatch table per instance
diff --git a/loader/loader.c b/loader/loader.c
index 737bf66..6064100 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -1242,6 +1242,7 @@
             for (i = 0; i < ptr_instance->extension_count; i++) {
                 free(ptr_instance->extension_names[i]);
             }
+            free(ptr_instance->disp);
             if (prev)
                 prev->next = next->next;
             else
diff --git a/loader/trampoline.c b/loader/trampoline.c
index 908b47d..7453f1b 100644
--- a/loader/trampoline.c
+++ b/loader/trampoline.c
@@ -70,9 +70,12 @@
             return VK_ERROR_OUT_OF_HOST_MEMORY;
         strcpy(ptr_instance->extension_names[i], pCreateInfo->ppEnabledExtensionNames[i]);
     }
+    ptr_instance->disp = malloc(sizeof(VkLayerInstanceDispatchTable));
+    if (ptr_instance->disp == NULL)
+        return VK_ERROR_OUT_OF_HOST_MEMORY;
+    memcpy(ptr_instance->disp, &instance_disp, sizeof(instance_disp));
     ptr_instance->next = loader.instances;
     loader.instances = ptr_instance;
-    ptr_instance->disp = &instance_disp;
     loader_activate_instance_layers(ptr_instance);
 
     res = instance_disp.CreateInstance(pCreateInfo, (VkInstance *) ptr_instance);