changeset 35338:4fe8922d6242

stream ftp: Create buffers before opening control connection
author al
date Tue, 20 Nov 2012 22:22:04 +0000
parents 6641819c8f45
children c7c59b8e3af8
files stream/stream_ftp.c
diffstat 1 files changed, 9 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/stream/stream_ftp.c	Tue Nov 20 22:20:52 2012 +0000
+++ b/stream/stream_ftp.c	Tue Nov 20 22:22:04 2012 +0000
@@ -430,6 +430,15 @@
     return STREAM_ERROR;
   }
 
+  // Allocate buffers
+  p->buf = malloc(BUFSIZE);
+
+  if (!p->buf) {
+    close_f(stream);
+    m_struct_free(&stream_opts,opts);
+    return STREAM_ERROR;
+  }
+
   // Open the control connection
   p->handle = connect2Server(p->host,p->port,1);
 
@@ -441,7 +450,6 @@
   // We got a connection, let's start serious things
   stream->fd = -1;
   stream->priv = p;
-  p->buf = malloc(BUFSIZE);
 
   if (readresp(p, NULL) == 0) {
     close_f(stream);