tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] tccpe.c / resolve_sym() leaks LoadLibrary() handles


From: egodust
Subject: [Tinycc-devel] tccpe.c / resolve_sym() leaks LoadLibrary() handles
Date: Mon, 28 Apr 2008 11:42:14 +0100

Heyas,

When a compiled TCC binary image is memory linked, resolve_sym() is
given the symbol to find, it looks
for the assocated DLL (using DEF file info) and calls LoadLibrary(),
using GetProcAddress() to get the function
pointer.

This is problematic:

1. LoadLibrary() is called, per symbol, if multiple symbols from the
same DLL are used, LoadLibrary() is called
    per symbol.

2. LoadLibrary() is referenced counted and might overflow for many symbols

3. FreeLibrary() is never called, which means the DLLs are not freed,
until process shutdown

Imagine an application has loaded a custom dll (foo.dll) which TCC
also LoadLibrary()s, the app then FreeLibrary()'s
    at some point, but resolve_sym() has messed with the refcnt so the
DLL can't be unloaded until exit(0)

-

resolve_sym() should defer loading libraries to another function which
keeps track of the DLLs that have
been LoadLibrary()'d, so that tcc_delete() can free them, it also
means that LoadLibrary() is only called
once per DLL when it needs to be mapped, and other symbols in the same
DLL use the same handle with
GetProcAddress()?

Kind Regards,
Sam




reply via email to

[Prev in Thread] Current Thread [Next in Thread]