[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnurl] 23/73: mime: improve unbinding top multipart from e
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnurl] 23/73: mime: improve unbinding top multipart from easy handle. |
Date: |
Tue, 24 Oct 2017 18:54:04 +0200 |
This is an automated email from the git hooks/post-receive script.
ng0 pushed a commit to branch master
in repository gnurl.
commit b557182db1622510ebba3344747b6787994a75e2
Author: Patrick Monnerat <address@hidden>
AuthorDate: Sun Oct 8 18:38:34 2017 +0100
mime: improve unbinding top multipart from easy handle.
Also avoid dangling pointers in referencing parts.
---
lib/mime.c | 51 +++++++++++++++++++++++++++++++++++++++++----------
lib/mime.h | 2 ++
lib/url.c | 5 ++---
3 files changed, 45 insertions(+), 13 deletions(-)
diff --git a/lib/mime.c b/lib/mime.c
index 7cfce6ae8..0759ad50e 100644
--- a/lib/mime.c
+++ b/lib/mime.c
@@ -1069,13 +1069,6 @@ static int mime_subparts_seek(void *instream, curl_off_t
offset, int whence)
return result;
}
-static void mime_subparts_free(void *ptr)
-{
- curl_mime *mime = (curl_mime *) ptr;
- curl_mime_free(mime);
-}
-
-
/* Release part content. */
static void cleanup_part_content(curl_mimepart *part)
{
@@ -1094,6 +1087,30 @@ static void cleanup_part_content(curl_mimepart *part)
part->kind = MIMEKIND_NONE;
}
+static void mime_subparts_free(void *ptr)
+{
+ curl_mime *mime = (curl_mime *) ptr;
+
+ if(mime && mime->parent) {
+ mime->parent->freefunc = NULL; /* Be sure we won't be called again. */
+ cleanup_part_content(mime->parent); /* Avoid dangling pointer in part. */
+ }
+ curl_mime_free(mime);
+}
+
+/* Do not free subparts: unbind them. This is used for the top level only. */
+static void mime_subparts_unbind(void *ptr)
+{
+ curl_mime *mime = (curl_mime *) ptr;
+
+ if(mime && mime->parent) {
+ mime->parent->freefunc = NULL; /* Be sure we won't be called again. */
+ cleanup_part_content(mime->parent); /* Avoid dangling pointer in part. */
+ mime->parent = NULL;
+ }
+}
+
+
void Curl_mime_cleanpart(curl_mimepart *part)
{
cleanup_part_content(part);
@@ -1390,8 +1407,8 @@ CURLcode curl_mime_data_cb(curl_mimepart *part,
curl_off_t datasize,
}
/* Set mime part content from subparts. */
-CURLcode curl_mime_subparts(curl_mimepart *part,
- curl_mime *subparts)
+CURLcode Curl_mime_set_subparts(curl_mimepart *part,
+ curl_mime *subparts, int take_ownership)
{
if(!part)
return CURLE_BAD_FUNCTION_ARGUMENT;
@@ -1414,7 +1431,7 @@ CURLcode curl_mime_subparts(curl_mimepart *part,
subparts->parent = part;
part->readfunc = mime_subparts_read;
part->seekfunc = mime_subparts_seek;
- part->freefunc = mime_subparts_free;
+ part->freefunc = take_ownership? mime_subparts_free: mime_subparts_unbind;
part->arg = subparts;
part->datasize = -1;
part->kind = MIMEKIND_MULTIPART;
@@ -1423,6 +1440,11 @@ CURLcode curl_mime_subparts(curl_mimepart *part,
return CURLE_OK;
}
+CURLcode curl_mime_subparts(curl_mimepart *part, curl_mime *subparts)
+{
+ return Curl_mime_set_subparts(part, subparts, TRUE);
+}
+
/* Readback from top mime. */
/* Argument is the dummy top part. */
@@ -1817,6 +1839,15 @@ void Curl_mime_cleanpart(curl_mimepart *part)
(void) part;
}
+CURLcode Curl_mime_set_subparts(curl_mimepart *part,
+ curl_mime *subparts, int take_ownership)
+{
+ (void) part;
+ (void) subparts;
+ (void) take_ownership;
+ return CURLE_NOT_BUILT_IN;
+}
+
CURLcode Curl_mime_prepare_headers(curl_mimepart *part,
const char *contenttype,
const char *disposition,
diff --git a/lib/mime.h b/lib/mime.h
index a14485707..7827f7412 100644
--- a/lib/mime.h
+++ b/lib/mime.h
@@ -122,6 +122,8 @@ struct curl_mimepart_s {
/* Prototypes. */
void Curl_mime_initpart(curl_mimepart *part, struct Curl_easy *easy);
void Curl_mime_cleanpart(curl_mimepart *part);
+CURLcode Curl_mime_set_subparts(curl_mimepart *part,
+ curl_mime *subparts, int take_ownership);
CURLcode Curl_mime_prepare_headers(curl_mimepart *part,
const char *contenttype,
const char *disposition,
diff --git a/lib/url.c b/lib/url.c
index 584635bc3..3b66ae33b 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -1158,10 +1158,9 @@ CURLcode Curl_setopt(struct Curl_easy *data, CURLoption
option,
/*
* Set to make us do MIME/form POST
*/
- result = curl_mime_subparts(&data->set.mimepost,
- va_arg(param, curl_mime *));
+ result = Curl_mime_set_subparts(&data->set.mimepost,
+ va_arg(param, curl_mime *), FALSE);
if(!result) {
- data->set.mimepost.freefunc = NULL; /* Avoid free upon easy cleanup. */
data->set.httpreq = HTTPREQ_POST_MIME;
data->set.opt_no_body = FALSE; /* this is implied */
}
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [gnurl] 17/73: remove_handle: call multi_done() first, then clear dns cache pointer, (continued)
- [GNUnet-SVN] [gnurl] 17/73: remove_handle: call multi_done() first, then clear dns cache pointer, gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 38/73: ftpserver: support case insensitive commands, gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 16/73: multi_done: wait for name resolve to finish if still ongoing, gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 06/73: docs: fix typo in curl_mime_data_cb man page, gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 11/73: strtoofft: Remove extraneous null check, gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 19/73: docs: clarify form/mime usage of non-regular data files., gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 66/73: test653: check reuse of easy handle after mime data change, gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 62/73: vtls: change struct Curl_ssl `close' field name to `close_one'., gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 57/73: setopt: range check most long options, gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 60/73: test652: curl_mime_data + base64 encoder with large contents, gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 23/73: mime: improve unbinding top multipart from easy handle.,
gnunet <=
- [GNUnet-SVN] [gnurl] 13/73: vtls: fix warnings with --disable-crypto-auth, gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 28/73: RTSP: avoid integer overflow on funny RTSP response, gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 18/73: Revert "multi_done: wait for name resolve to finish if still ongoing", gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 37/73: smtp_done: free data before returning (on send failure), gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 21/73: curlver.h: next expected release is 7.57.0, gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 27/73: ftpserver: properly reset $ftptargetdir., gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 36/73: FTP: URL decode path for dir listing in nocwd mode, gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 31/73: openssl: enable PKCS12 support for !BoringSSL, gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 40/73: openssl: don't use old BORINGSSL_YYYYMM macros, gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 41/73: url: Update current connection SSL verify params in setopt, gnunet, 2017/10/24