From e6c01555670c6a5f8dc68ea66be3bb3d0477f642 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Wed, 22 Apr 2009 15:06:28 +0000 Subject: Add more error checks to sftp_message_new(). git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@574 7dcaeef0-15fb-0310-b436-a5af3365683c --- libssh/sftp.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/libssh/sftp.c b/libssh/sftp.c index 02032ff..d3b0675 100644 --- a/libssh/sftp.c +++ b/libssh/sftp.c @@ -284,20 +284,25 @@ int sftp_get_error(SFTP_SESSION *sftp) { } static SFTP_MESSAGE *sftp_message_new(SFTP_SESSION *sftp){ - SFTP_MESSAGE *msg; + SFTP_MESSAGE *msg = NULL; - sftp_enter_function(); + sftp_enter_function(); - msg = malloc(sizeof(SFTP_MESSAGE)); - if (msg == NULL) { - return NULL; - } + msg = malloc(sizeof(SFTP_MESSAGE)); + if (msg == NULL) { + return NULL; + } + ZERO_STRUCTP(msg); - memset(msg,0,sizeof(*msg)); - msg->payload=buffer_new(); - msg->sftp=sftp; - sftp_leave_function(); - return msg; + msg->payload = buffer_new(); + if (msg->payload == NULL) { + SAFE_FREE(msg); + return NULL; + } + msg->sftp = sftp; + + sftp_leave_function(); + return msg; } static void sftp_message_free(SFTP_MESSAGE *msg){ -- cgit