merces / libpe

The PE library used by @merces/pev
http://pev.sf.net
GNU Lesser General Public License v3.0
115 stars 40 forks source link

Fix memory leak and compiler warnings #40

Open GoGoOtaku opened 1 year ago

GoGoOtaku commented 1 year ago

This looks bigger than it actually is. From what I can tell I have now fixed every memory leak in pev. At least with my test executable (putty.exe). None of them were major obviously but better have them fixed. I also fixed all warnings GCC gave me (except for libudis86 stuff).

The reason why I put pe_ctx_t and pe_resources_t into their own headers is because redefinition of typedefs is technically a C11 feature. This lead to a warning every time pe.h was used.

Another warning I fixed is harder to explain because it is platform specific: In hashes.c IMAGE_ORDINAL_FLAG64 was used as a macro with the UL postfix aka unsigned long. This was then (rightfully) fed into PRIu64 which is a macro to print a 64 bit integer based on the current system. This works fine under windows as under Windows an uint64_t is extended to unsigned long int. Under Linux however it extents to unsigned long long int. Technically both are 64 bit under Linux but it still gives a Wformat warning (I don't make the rules). Thus I have changed the macro into a static const uint64_t. This is more in line with what we want (specifically an unsigned 64 bit integer), it's more platform independent and as a side effect it's also more debugger friendly. The cast to uint64_t of the logic and result is for the same reason but should have no effect on the actual compiled library.

The rest of the warnings are more self explanatory.