summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-04-22 15:06:28 +0000
committerAndreas Schneider <mail@cynapses.org>2009-04-22 15:06:28 +0000
commite6c01555670c6a5f8dc68ea66be3bb3d0477f642 (patch)
tree213d7ceb255801d1dfcb8c9f3d2197487decc7be
parentea59faaec9b4cff041de76e225a08b5be2f11799 (diff)
downloadlibssh-e6c01555670c6a5f8dc68ea66be3bb3d0477f642.tar.gz
libssh-e6c01555670c6a5f8dc68ea66be3bb3d0477f642.tar.xz
libssh-e6c01555670c6a5f8dc68ea66be3bb3d0477f642.zip
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
-rw-r--r--libssh/sftp.c27
1 files 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){