mimepost: allocate main struct on-demand

This makes the easy handle 432 bytes smaller (totally 5352 bytes on my
rather maximized Linux 64 bit build). The 440 byte mimepost struct is
now allocated only when needed.

Closes #20260
This commit is contained in:
Daniel Stenberg 2026-01-12 09:30:25 +01:00
parent 9e0b02c19c
commit 44312b4b11
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
9 changed files with 79 additions and 45 deletions

View file

@ -1383,6 +1383,38 @@ static CURLcode setopt_slist(struct Curl_easy *data, CURLoption option,
return result;
}
#if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_SMTP) || \
!defined(CURL_DISABLE_IMAP)
# ifndef CURL_DISABLE_MIME
static CURLcode setopt_mimepost(struct Curl_easy *data, curl_mime *mimep)
{
/*
* Set to make us do MIME POST
*/
CURLcode result;
struct UserDefined *s = &data->set;
if(!s->mimepostp) {
s->mimepostp = curlx_malloc(sizeof(*s->mimepostp));
if(!s->mimepostp)
return CURLE_OUT_OF_MEMORY;
Curl_mime_initpart(s->mimepostp);
}
result = Curl_mime_set_subparts(s->mimepostp, mimep, FALSE);
if(!result) {
s->method = HTTPREQ_POST_MIME;
s->opt_no_body = FALSE; /* this is implied */
#ifndef CURL_DISABLE_FORM_API
Curl_mime_cleanpart(data->state.formp);
Curl_safefree(data->state.formp);
data->state.mimepost = NULL;
#endif
}
return result;
}
#endif /* !CURL_DISABLE_MIME */
#endif /* !CURL_DISABLE_HTTP || !CURL_DISABLE_SMTP || !CURL_DISABLE_IMAP */
/* assorted pointer type arguments */
static CURLcode setopt_pointers(struct Curl_easy *data, CURLoption option,
va_list param)
@ -1405,25 +1437,11 @@ static CURLcode setopt_pointers(struct Curl_easy *data, CURLoption option,
break;
#endif /* !CURL_DISABLE_FORM_API */
#endif /* !CURL_DISABLE_HTTP */
#if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_SMTP) || \
#if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_SMTP) || \
!defined(CURL_DISABLE_IMAP)
# ifndef CURL_DISABLE_MIME
case CURLOPT_MIMEPOST:
/*
* Set to make us do MIME POST
*/
result = Curl_mime_set_subparts(&s->mimepost,
va_arg(param, curl_mime *),
FALSE);
if(!result) {
s->method = HTTPREQ_POST_MIME;
s->opt_no_body = FALSE; /* this is implied */
#ifndef CURL_DISABLE_FORM_API
Curl_mime_cleanpart(data->state.formp);
Curl_safefree(data->state.formp);
data->state.mimepost = NULL;
#endif
}
result = setopt_mimepost(data, va_arg(param, curl_mime *));
break;
#endif /* !CURL_DISABLE_MIME */
#endif /* !CURL_DISABLE_HTTP || !CURL_DISABLE_SMTP || !CURL_DISABLE_IMAP */