Subject: Re: [PATCH] Support for exit-signal messages

Re: [PATCH] Support for exit-signal messages

From: Simon Josefsson <simon_at_josefsson.org>
Date: Tue, 05 Oct 2010 12:02:22 +0200

Tommy Lindgren <tommy.lindgren_at_gmail.com> writes:

> The function is always returning LIBSSH2_ERROR_NONE. I'm not sure if
> it should returning anything else? (Perhaps if the malloc fails? Other
> API functions don't seem to do this though.)

It needs to handle memory allocation errors and return
LIBSSH2_ERROR_ALLOC when it happens. Something like this:

        s = LIBSSH2_ALLOC(session, len);
        if (!s) {
            return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
                                  "Unable to allocate memory for foo");
        }

> I'm slightly confused about returning pointers to allocated buffers
> though. The man page for libssh2_base64_decode says that the calling
> function can't free the memory in a reliable way. Why is that?

It can be issue under Windows when multiple runtime libraries are used
(one runtime library cannot free memory maintained by another runtime
library). The workaround is for the application to provide malloc/free
callbacks. Possibly libssh2 should have a 'libssh2_free' function.

/Simon
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2010-10-05