]> granicus.if.org Git - curl/commitdiff
Fixed an OOM problem with file: URLs
authorDan Fandrich <dan@coneharvesters.com>
Tue, 30 Oct 2007 23:00:40 +0000 (23:00 +0000)
committerDan Fandrich <dan@coneharvesters.com>
Tue, 30 Oct 2007 23:00:40 +0000 (23:00 +0000)
Moved Curl_file_connect into the protocol handler struct.

CHANGES
lib/file.c
lib/file.h
lib/url.c

diff --git a/CHANGES b/CHANGES
index db22ab03e8919c7e9bf2ee9586039deddb358891..1819929d87c0ed16d1fafafd3bc8a4e9b864ebe3 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,11 @@
 
                                   Changelog
 
+Dan F (30 October 2007)
+- Fixed an OOM problem with file: URLs
+
+- Moved Curl_file_connect into the protocol handler struct
+
 Dan F (29 October 2007)
 - Added test case 546 to check that subsequent FTP transfers work after a
   failed one using the multi interface
index 0bc0e4942748490dbd52246db7f1f2f2d1865936..f344404dbf60d55be8d8efec7fa865f09a3995e6 100644 (file)
@@ -97,6 +97,7 @@
 static CURLcode Curl_file(struct connectdata *, bool *done);
 static CURLcode Curl_file_done(struct connectdata *conn,
                                CURLcode status, bool premature);
+static CURLcode Curl_file_connect(struct connectdata *conn, bool *done);
 
 /*
  * FILE scheme handler.
@@ -108,7 +109,7 @@ const struct Curl_handler Curl_handler_file = {
   Curl_file,                            /* do_it */
   Curl_file_done,                       /* done */
   ZERO_NULL,                            /* do_more */
-  ZERO_NULL,                            /* connect_it */
+  Curl_file_connect,                    /* connect_it */
   ZERO_NULL,                            /* connecting */
   ZERO_NULL,                            /* doing */
   ZERO_NULL,                            /* proto_getsock */
@@ -123,7 +124,7 @@ const struct Curl_handler Curl_handler_file = {
  * do protocol-specific actions at connect-time.  We emulate a
  * connect-then-transfer protocol and "connect" to the file here
  */
-CURLcode Curl_file_connect(struct connectdata *conn)
+static CURLcode Curl_file_connect(struct connectdata *conn, bool *done)
 {
   struct SessionHandle *data = conn->data;
   char *real_path = curl_easy_unescape(data, data->reqdata.path, 0, NULL);
@@ -203,6 +204,7 @@ CURLcode Curl_file_connect(struct connectdata *conn)
     Curl_file_done(conn, CURLE_FILE_COULDNT_READ_FILE, FALSE);
     return CURLE_FILE_COULDNT_READ_FILE;
   }
+  *done = TRUE;
 
   return CURLE_OK;
 }
@@ -218,9 +220,6 @@ static CURLcode Curl_file_done(struct connectdata *conn,
   if(file->fd != -1)
     close(file->fd);
 
-  free(file);
-  conn->data->reqdata.proto.file= NULL; /* clear it! */
-
   return CURLE_OK;
 }
 
index 7f338af1ad524a4cd1f780583e2c1bae7765385b..f77972094059aa1ffc49ba1aede2680f2db90e68 100644 (file)
@@ -25,7 +25,5 @@
  ***************************************************************************/
 #ifndef CURL_DISABLE_FILE
 extern const struct Curl_handler Curl_handler_file;
-
-CURLcode Curl_file_connect(struct connectdata *);
 #endif
 #endif
index be8bad35f5168783673cae98f1e4a163451fa807..d122a90fbb6a6b867189d5a1e55759f2422977f2 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -3638,10 +3638,12 @@ static CURLcode CreateConnection(struct SessionHandle *data,
    * file: is a special case in that it doesn't need a network connection
    ***********************************************************************/
 #ifndef CURL_DISABLE_FILE
-  if (strequal(conn->protostr, "FILE")) {
+  if(conn->protocol & PROT_FILE) {
+    bool done;
     /* this is supposed to be the connect function so we better at least check
        that the file is present here! */
-    result = Curl_file_connect(conn);
+    DEBUGASSERT(conn->handler->connect_it);
+    result = conn->handler->connect_it(conn, &done);
 
     /* Setup a "faked" transfer that'll do nothing */
     if(CURLE_OK == result) {
@@ -3652,8 +3654,8 @@ static CURLcode CreateConnection(struct SessionHandle *data,
 
       result = setup_range(data);
       if(result) {
-        if(conn->handler->done)
-          result = conn->handler->done(conn, result, FALSE);
+        DEBUGASSERT(conn->handler->done);
+        conn->handler->done(conn, result, FALSE);
         return result;
       }