1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-11-23 01:22:37 +03:00

_libssh2_error: Support allocating the error message

Before this patch "_libssh2_error" required the error message to be a
static string.

This patch adds a new function "_libssh2_error_flags" accepting an
additional "flags" argument and specifically the flag
"LIBSSH2_ERR_FLAG_DUP" indicating that the passed string must be
duplicated into the heap.

Then, the method "_libssh2_error" has been rewritten to use that new
function under the hood.

Signed-off-by: Salvador Fandino <sfandino@yahoo.com>
Signed-off-by: Salvador Fandiño <sfandino@yahoo.com>
This commit is contained in:
Salvador Fandino
2015-10-21 15:03:02 +02:00
committed by Daniel Stenberg
parent d441da3086
commit ad23faaae6
4 changed files with 37 additions and 2 deletions

View File

@@ -1058,6 +1058,11 @@ session_free(LIBSSH2_SESSION *session)
LIBSSH2_FREE(session, session->server_hostkey);
}
/* error string */
if (session->err_msg && ((session->err_flags & LIBSSH2_ERR_FLAG_DUP) != 0)) {
LIBSSH2_FREE(session, (char *)session->err_msg);
}
LIBSSH2_FREE(session, session);
return 0;