Skip to content

Commit 70bff29

Browse files
committed
Corrected minor bug of memory leak in the destruction of the proxy loader.
1 parent b1331eb commit 70bff29

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

source/loader/source/loader.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct loader_initialization_order_type
6161

6262
struct loader_type
6363
{
64+
loader_impl proxy; /* Points to the internal proxy loader */
6465
set impl_map; /* Maps the loader implementations by tag */
6566
vector initialization_order; /* Stores the loader implementations by order of initialization (used for destruction) */
6667
uint64_t init_thread_id; /* Stores the thread id of the thread that initialized metacall */
@@ -106,7 +107,7 @@ static int loader_metadata_cb_iterate(set s, set_key key, set_value val, set_cb_
106107
/* -- Member Data -- */
107108

108109
static struct loader_type loader_instance_default = {
109-
NULL, NULL, THREAD_ID_INVALID
110+
NULL, NULL, NULL, THREAD_ID_INVALID
110111
};
111112

112113
static loader loader_instance_ptr = &loader_instance_default;
@@ -140,21 +141,19 @@ void loader_initialize_proxy()
140141

141142
if (set_get(l->impl_map, (set_key)LOADER_HOST_PROXY_NAME) == NULL)
142143
{
143-
loader_impl proxy;
144+
l->proxy = loader_impl_create_proxy();
144145

145-
proxy = loader_impl_create_proxy();
146-
147-
if (proxy != NULL)
146+
if (l->proxy != NULL)
148147
{
149-
if (set_insert(l->impl_map, (set_key)loader_impl_tag(proxy), proxy) != 0)
148+
if (set_insert(l->impl_map, (set_key)loader_impl_tag(l->proxy), l->proxy) != 0)
150149
{
151-
log_write("metacall", LOG_LEVEL_ERROR, "Loader invalid proxy insertion <%p>", (void *)proxy);
150+
log_write("metacall", LOG_LEVEL_ERROR, "Loader invalid proxy insertion <%p>", (void *)l->proxy);
152151

153-
loader_impl_destroy(proxy);
152+
loader_impl_destroy(l->proxy);
154153
}
155154

156155
/* Insert into destruction list */
157-
loader_initialization_register(proxy);
156+
loader_initialization_register(l->proxy);
158157

159158
log_write("metacall", LOG_LEVEL_DEBUG, "Loader proxy initialized");
160159
}
@@ -798,7 +797,10 @@ void loader_unload_children(loader_impl impl)
798797
log_write("metacall", LOG_LEVEL_DEBUG, "Loader unloading (%s)", loader_impl_tag(order->impl));
799798

800799
/* Call recursively for deletion of children */
801-
loader_impl_destroy(order->impl);
800+
if (order->impl != l->proxy)
801+
{
802+
loader_impl_destroy(order->impl);
803+
}
802804

803805
/* Clear current order */
804806
order->being_deleted = 1;
@@ -839,6 +841,14 @@ int loader_unload()
839841
}
840842

841843
loader_unload_children(NULL);
844+
845+
/* The proxy is the first loader, it must be destroyed at the end */
846+
if (l->proxy != NULL)
847+
{
848+
loader_impl_destroy_objects(l->proxy);
849+
loader_impl_destroy(l->proxy);
850+
l->proxy = NULL;
851+
}
842852
}
843853

844854
/* Clear the implementation tag map */

0 commit comments

Comments
 (0)