-
Notifications
You must be signed in to change notification settings - Fork 106
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
Windows/Shared lib/Dll: clib free can't be used on string-results with non shared CRT #2527
Comments
May i know which compiler are you using on windows? |
VS2022 up-to-date, x64, Debug -> using a VS2022 build of Kuzu current git
it should not crash if both Kuzu and the App are sharing the same CRT else it needs to crash i got this error in the output:
what more or less means that its not on this heap this check happens only in Debug Release silently ignores that because then the Debug/HeapValidation is not active (there is still the problem that the Kuzu buils is using the Release CRT and my application is using the Debug CRT - i think they can't share data) - so Release works due to same Release CRT https://learn.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library?view=msvc-170 but this is all unrelevant if the DLL provides a "free" functions then all cases are working |
We will rework C API a bit to provide a destructor function for all the values we return, so that the user can destruct the values we return even if it is allocated by a different version of malloc. |
its not solveable by linking with other libs on kuzu side the differences on linux are smaller - but only due to different default behavior - mostly shared heaps and nearly no differences between Release/Debug builds (when not using different check flags as i explained) for a C++ API its common(and needed because of missing ABI-Standard) to use the same compiler (what makes it implicitly someway (when CRTs are shared) compatible) but a C API should not depend on using the same compiler/same CRT - thats the reason for having a C API - for not beeing dependent at all the C API is not independent if its needed that the dll/so of Kuzu NEEDS to share the same CRT with the application - and only this would allow a free of a Kuzu string in my own application and this is not a Windows-special - its only not that super common on linux - but getting still a problem when switching stdc++ lib or using more check-flags etc. - what many developers just miss to do and i have technically no chance of having the same CRT if i write a Java or C#, Python Wrapper on top of the Kuzu C API - thats the reason for having free-Routines in C APIs some developers tend to think that "it seem to work" is some sort of guarantee :) |
I believe this has been fixed in #2815 (with more work following that up in #3457, better described in #3133). There is now a Lines 1452 to 1459 in bc8213e
|
the question is why not kuzu_destroy - anything that gets allocated inside Kuzu dll needs to be freed - not only strings
its not prefered - its needed - or else your using code is dependent on how Kuzu is linked to the project and maybe you're not responsible for that in your project |
I think we have now provide a destroy function for everything allocated by kuzu C API (if you search for If there is anything still missing, let us know. |
all C-API routines that internaly using
convertToOwnedCString
can't be freed on application side using free(will crash due to different heaps in application and dll) - under linux sharing is default - on windows its mostly not
thats why most other C libaries like openssl, curl, ... have such "free" functions in their API
crash on free of kuzu_value_get_string result
these seems to alloc on dll side the string:
there needs to be something like a kuzu_free(void*) or kuzu_string_free(char*) to make destroying safe
would be also great to have functions that do not allocate but filling a string buffer on the application side
so as alternative to:
char *name2 = kuzu_value_get_string(value);
also
The text was updated successfully, but these errors were encountered: