Curl_send: return error when pre_receive_plain can't malloc

... will probably trigger some false DEAD CODE positives on non-windows
code analyzers for the conditional code.

Closes #6011
This commit is contained in:
Daniel Stenberg 2020-09-25 00:12:10 +02:00
Родитель 1397a7de6e
Коммит 92a9b88ebf
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 5CC908FDB71E12C2
1 изменённых файлов: 9 добавлений и 3 удалений

Просмотреть файл

@ -140,7 +140,7 @@ bool Curl_recv_has_postponed_data(struct connectdata *conn, int sockindex)
psnd->recv_size > psnd->recv_processed; psnd->recv_size > psnd->recv_processed;
} }
static void pre_receive_plain(struct connectdata *conn, int num) static CURLcode pre_receive_plain(struct connectdata *conn, int num)
{ {
const curl_socket_t sockfd = conn->sock[num]; const curl_socket_t sockfd = conn->sock[num];
struct postponed_data * const psnd = &(conn->postponed[num]); struct postponed_data * const psnd = &(conn->postponed[num]);
@ -161,6 +161,8 @@ static void pre_receive_plain(struct connectdata *conn, int num)
/* Use buffer double default size for intermediate buffer */ /* Use buffer double default size for intermediate buffer */
psnd->allocated_size = 2 * conn->data->set.buffer_size; psnd->allocated_size = 2 * conn->data->set.buffer_size;
psnd->buffer = malloc(psnd->allocated_size); psnd->buffer = malloc(psnd->allocated_size);
if(!psnd->buffer)
return CURLE_OUT_OF_MEMORY;
psnd->recv_size = 0; psnd->recv_size = 0;
psnd->recv_processed = 0; psnd->recv_processed = 0;
#ifdef DEBUGBUILD #ifdef DEBUGBUILD
@ -180,6 +182,7 @@ static void pre_receive_plain(struct connectdata *conn, int num)
psnd->allocated_size = 0; psnd->allocated_size = 0;
} }
} }
return CURLE_OK;
} }
static ssize_t get_pre_recved(struct connectdata *conn, int num, char *buf, static ssize_t get_pre_recved(struct connectdata *conn, int num, char *buf,
@ -225,7 +228,7 @@ bool Curl_recv_has_postponed_data(struct connectdata *conn, int sockindex)
(void)sockindex; (void)sockindex;
return false; return false;
} }
#define pre_receive_plain(c,n) do {} while(0) #define pre_receive_plain(c,n) CURLE_OK
#define get_pre_recved(c,n,b,l) 0 #define get_pre_recved(c,n,b,l) 0
#endif /* ! USE_RECV_BEFORE_SEND_WORKAROUND */ #endif /* ! USE_RECV_BEFORE_SEND_WORKAROUND */
@ -379,7 +382,10 @@ ssize_t Curl_send_plain(struct connectdata *conn, int num,
To avoid lossage of received data, recv() must be To avoid lossage of received data, recv() must be
performed before every send() if any incoming data is performed before every send() if any incoming data is
available. */ available. */
pre_receive_plain(conn, num); if(pre_receive_plain(conn, num)) {
*code = CURLE_OUT_OF_MEMORY;
return -1;
}
#if defined(MSG_FASTOPEN) && !defined(TCP_FASTOPEN_CONNECT) /* Linux */ #if defined(MSG_FASTOPEN) && !defined(TCP_FASTOPEN_CONNECT) /* Linux */
if(conn->bits.tcp_fastopen) { if(conn->bits.tcp_fastopen) {