-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using SoapySDRArgInfoList_clear()
on an ArgInfoList
results in invalid free()
#361
Comments
IIRC initializing a On the C side we have toArgInfoList(), using toArgInfo(), using toCString(), and there is an alloc there, right? So SoapySDRArgInfo_clear() and SoapySDRArgInfoList_clear() shouldn't be any trouble? |
Oh, I see you say "borrowed". Note that |
Ah, that might be part of the problem; we're using the C bindings (since we are coming from a higher-level language) so we don't actually call the C++ functions, we call the C functions directly. I assumed that this was the preferred method of interacting with |
So in C++, Now for the C bindings,
In either language, the caller owns the result. Either is fine, I dont think there is a preferred option.
It should not matter however the getSettingInfo was implemented, const strings or not. The result is actually copied into a std::string held by the structure in C++. And then for the C bindings, that std::string is copied again into the C structure/arrays with strdup()
I dont think the cause is const strings in the driver, but there could be a bug. Do you have a backtrace of the failed call to 'free()'? Is there any chance some prior code called free() on the pointer returned by |
Note the "borrowed", I assume that SoapySDRArgInfo struct was filled by custom code and of course
|
Sorry, I dug into this further thanks to your pointers, and I noted that we ourselves were accidentally freeing one of the strings in the object within one of our debugging routines. Terribly sorry for the noise! |
X-ref: JuliaTelecom/SoapySDR.jl#58 |
We built a SoapySDR loopback module for internal testing, based off of the rtlsdr codebase. During implementation, we borrowed the structure of functions such as
getSettingInfo
, however we've noticed that, after obtaining the argument info lists viaSoapySDRDevice_getSettingInfo()
, if we then try to free the list viaSoapySDRArgInfoList_clear()
, there is an invalidfree()
triggered upon the freeing of the string pointers. We believe this is due to the usage of string literals being assigned to thechar *
elements of theArgInfoList
structure, followed by thesefree()
calls.I see two possible ways forward:
strdup()
such that thosefree()
calls are operating on actually allocated memory.free()
calls somehow; either by never freeing such strings, or by embedding a bitmap that enables/disables freeing of certain pieces of memory.In practice, I doubt many users are calling this function in a loop, so perhaps the memory accounting here is not so necessary for usual use. I just hate to see a memory leak anywhere.
The text was updated successfully, but these errors were encountered: