fix: use signer's own Free() instead of system libc free on Windows#135
Open
fix: use signer's own Free() instead of system libc free on Windows#135
Conversation
On Windows, ctypes.util.find_library('c') returns msvcrt.dll, but the Go
signer DLL (cross-compiled with MinGW) may use a different C runtime or
statically link its own CRT. Calling msvcrt's free() on memory allocated
by a different CRT's malloc() is undefined behavior (crashes, heap
corruption). Fix by using the signer's own exported Free() function which
is guaranteed to use the matching allocator.
Requires the corresponding lighter-go change that exports the Free function.
Co-Authored-By: Mihail <mlavric64@gmail.com>
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a Windows crash/heap corruption caused by cross-CRT memory freeing. The previous code used
ctypes.util.find_library("c")(vialibc.py) to find the system C library'sfree(), which returnsmsvcrt.dllon Windows. However, the Go signer DLL is cross-compiled with MinGW and may use a different C runtime (or statically link its own). Calling one CRT'sfree()on memory allocated by another CRT'smalloc()is undefined behavior on Windows.The fix replaces
libc.free()with the signer's own exportedFree()function, which is guaranteed to use the same allocator thatC.CString()used to allocate the memory.Requires the companion PR in lighter-go (elliottech/lighter-go#56) which exports the
Freefunction, and the signer binaries inlighter/signers/must be rebuilt from that updated lighter-go before this change will work.Review & Testing Checklist for Human
.dll,.so,.dylib) inlighter/signers/must be rebuilt from the updated lighter-go that exportsFreebefore merging this PR. Without that,__populate_shared_library_functionswill fail at thesigner.Freeline because the symbol won't exist.decode_and_freeis never called beforeget_signer()— the code references the module-level__signerdirectly, which isNoneuntilget_signer()runs. Current call flow looks safe but worth confirming.GenerateAPIKey,create_order) work without crashes or heap corruption.lighter/libc.pyis now unused dead code — consider removing it in a follow-up.Notes
free()happened to work. The new approach is correct on all platforms.libc.pymodule is no longer imported anywhere but was not deleted in this PR to keep the diff minimal.Requested by: @lavrric