diff --git a/lighter/signer_client.py b/lighter/signer_client.py index 2734f85..0da893f 100644 --- a/lighter/signer_client.py +++ b/lighter/signer_client.py @@ -20,7 +20,6 @@ from lighter.models.resp_send_tx import RespSendTx from lighter.models.resp_send_tx_batch import RespSendTxBatch from lighter.transactions import CreateOrder, CancelOrder, Withdraw, CreateGroupedOrders -from lighter.libc import free CODE_OK = 200 @@ -99,8 +98,10 @@ def decode_and_free(ptr: Any) -> Optional[str]: return c_str.decode('utf-8') return None finally: - # Free the memory allocated by the C library - free(ptr) + # Free the memory using the signer's own Free function to ensure + # the same C runtime that allocated the memory also frees it. + # This is critical on Windows where different CRTs have separate heaps. + __signer.Free(ptr) def __populate_shared_library_functions(signer): @@ -174,6 +175,9 @@ def __populate_shared_library_functions(signer): signer.SignApproveIntegrator.argtypes = [ctypes.c_longlong, ctypes.c_uint32, ctypes.c_uint32, ctypes.c_uint32, ctypes.c_uint32, ctypes.c_longlong, ctypes.c_longlong, ctypes.c_int, ctypes.c_longlong] signer.SignApproveIntegrator.restype = SignedTxResponse + signer.Free.argtypes = [ctypes.c_void_p] + signer.Free.restype = None + def get_signer(): # check if singleton exists already diff --git a/lighter/signers/lighter-signer-darwin-arm64.dylib b/lighter/signers/lighter-signer-darwin-arm64.dylib index 822bbfb..58f2023 100644 Binary files a/lighter/signers/lighter-signer-darwin-arm64.dylib and b/lighter/signers/lighter-signer-darwin-arm64.dylib differ diff --git a/lighter/signers/lighter-signer-darwin-arm64.h b/lighter/signers/lighter-signer-darwin-arm64.h index 1772296..edd9ecd 100644 --- a/lighter/signers/lighter-signer-darwin-arm64.h +++ b/lighter/signers/lighter-signer-darwin-arm64.h @@ -144,6 +144,7 @@ extern SignedTxResponse SignUpdateMargin(int cMarketIndex, long long cUSDCAmount extern SignedTxResponse SignStakeAssets(long long cStakingPoolIndex, long long cShareAmount, long long cNonce, int cApiKeyIndex, long long cAccountIndex); extern SignedTxResponse SignUnstakeAssets(long long cStakingPoolIndex, long long cShareAmount, long long cNonce, int cApiKeyIndex, long long cAccountIndex); extern SignedTxResponse SignApproveIntegrator(long long cIntegratorIndex, uint32_t cMaxPerpsTakerFee, uint32_t cMaxPerpsMakerFee, uint32_t cMaxSpotTakerFee, uint32_t cMaxSpotMakerFee, long long cApprovalExpiry, long long cNonce, int cApiKeyIndex, long long cAccountIndex); +extern void Free(void* ptr); #ifdef __cplusplus } diff --git a/lighter/signers/lighter-signer-linux-amd64.h b/lighter/signers/lighter-signer-linux-amd64.h index 37b97d6..d14c8d4 100644 --- a/lighter/signers/lighter-signer-linux-amd64.h +++ b/lighter/signers/lighter-signer-linux-amd64.h @@ -136,6 +136,7 @@ extern SignedTxResponse SignUpdateMargin(int cMarketIndex, long long int cUSDCAm extern SignedTxResponse SignStakeAssets(long long int cStakingPoolIndex, long long int cShareAmount, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex); extern SignedTxResponse SignUnstakeAssets(long long int cStakingPoolIndex, long long int cShareAmount, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex); extern SignedTxResponse SignApproveIntegrator(long long int cIntegratorIndex, uint32_t cMaxPerpsTakerFee, uint32_t cMaxPerpsMakerFee, uint32_t cMaxSpotTakerFee, uint32_t cMaxSpotMakerFee, long long int cApprovalExpiry, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex); +extern void Free(void* ptr); #ifdef __cplusplus } diff --git a/lighter/signers/lighter-signer-linux-amd64.so b/lighter/signers/lighter-signer-linux-amd64.so index da328c2..bcbe58d 100644 Binary files a/lighter/signers/lighter-signer-linux-amd64.so and b/lighter/signers/lighter-signer-linux-amd64.so differ diff --git a/lighter/signers/lighter-signer-linux-arm64.h b/lighter/signers/lighter-signer-linux-arm64.h index 37b97d6..d14c8d4 100644 --- a/lighter/signers/lighter-signer-linux-arm64.h +++ b/lighter/signers/lighter-signer-linux-arm64.h @@ -136,6 +136,7 @@ extern SignedTxResponse SignUpdateMargin(int cMarketIndex, long long int cUSDCAm extern SignedTxResponse SignStakeAssets(long long int cStakingPoolIndex, long long int cShareAmount, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex); extern SignedTxResponse SignUnstakeAssets(long long int cStakingPoolIndex, long long int cShareAmount, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex); extern SignedTxResponse SignApproveIntegrator(long long int cIntegratorIndex, uint32_t cMaxPerpsTakerFee, uint32_t cMaxPerpsMakerFee, uint32_t cMaxSpotTakerFee, uint32_t cMaxSpotMakerFee, long long int cApprovalExpiry, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex); +extern void Free(void* ptr); #ifdef __cplusplus } diff --git a/lighter/signers/lighter-signer-linux-arm64.so b/lighter/signers/lighter-signer-linux-arm64.so index d336bb2..6b68e88 100644 Binary files a/lighter/signers/lighter-signer-linux-arm64.so and b/lighter/signers/lighter-signer-linux-arm64.so differ diff --git a/lighter/signers/lighter-signer-windows-amd64.dll b/lighter/signers/lighter-signer-windows-amd64.dll index 1cba0ae..dd5aeaa 100644 Binary files a/lighter/signers/lighter-signer-windows-amd64.dll and b/lighter/signers/lighter-signer-windows-amd64.dll differ diff --git a/lighter/signers/lighter-signer-windows-amd64.h b/lighter/signers/lighter-signer-windows-amd64.h index 9537538..b02057a 100644 --- a/lighter/signers/lighter-signer-windows-amd64.h +++ b/lighter/signers/lighter-signer-windows-amd64.h @@ -136,6 +136,7 @@ extern __declspec(dllexport) SignedTxResponse SignUpdateMargin(int cMarketIndex, extern __declspec(dllexport) SignedTxResponse SignStakeAssets(long long int cStakingPoolIndex, long long int cShareAmount, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex); extern __declspec(dllexport) SignedTxResponse SignUnstakeAssets(long long int cStakingPoolIndex, long long int cShareAmount, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex); extern __declspec(dllexport) SignedTxResponse SignApproveIntegrator(long long int cIntegratorIndex, uint32_t cMaxPerpsTakerFee, uint32_t cMaxPerpsMakerFee, uint32_t cMaxSpotTakerFee, uint32_t cMaxSpotMakerFee, long long int cApprovalExpiry, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex); +extern __declspec(dllexport) void Free(void* ptr); #ifdef __cplusplus }