Page MenuHomePhabricator

Returned allocated memory needs to be freed by the library as well
Open, Needs TriagePublic

Description

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.

Event Timeline

Jakuje added a project: Restricted Project.Feb 3 2021, 4:55 PM
Jakuje added a subscriber: Jakuje.

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.

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.