T268: Returned allocated memory needs to be freed by the library as well
Description
Originally reported by bagder: https://bugs.libssh.org/T268
The libssh API says in several places that the user needs to free returned elements. For example ssh_pki_export_pubkey_base64
.
However, in Windows and other systems, the heap allocator may be different in the library and in the code using the library, so calling free()
in the application on data returned from the library is not necessarily going to work.
libssh should therefor, to maximize portability and minimize friction, rather provide a libssh_free()
function that we can call which frees the memory with the same heap allocator that allocated the memory.
Comments:
Jakuje commented on 2021-02-03 15:55:54 UTC:
Thank you for a suggestion. This sounds like a good idea. Do you want to submit a merge request with this functionality in https://gitlab.com/libssh/libssh-mirror ? We already have some *_free()
functions for our objects already, but I do not think there is a generic one for simple objects/bytes.
For naming, I would be for ssh_object_free()
or something like this, as ssh_free()
is already taken.
Jakuje commented on 2021-03-26 13:08:16 UTC:
I was searching for this some time ago and found a function ssh_string_free_char()
. Would it solve your issue?
Indeed, we should update documentation to reference this function in documentation of ssh_pki_export_pubkey_base64()
or others.