aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_tcp.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-07-20 11:11:39 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-07-20 11:11:39 +0100
commit3a4ccea2afbaf5605faca23b46ab77d0efc353e6 (patch)
tree08bb6c76f146ce95f6fd96f8aa2f2c597fd358dc /src/lua/lua_tcp.c
parente808825b430161fe52a861f2098a873d5866b5e5 (diff)
downloadrspamd-3a4ccea2afbaf5605faca23b46ab77d0efc353e6.tar.gz
rspamd-3a4ccea2afbaf5605faca23b46ab77d0efc353e6.zip
[Minor] Do not use alloca for huge allocations
Diffstat (limited to 'src/lua/lua_tcp.c')
-rw-r--r--src/lua/lua_tcp.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/lua/lua_tcp.c b/src/lua/lua_tcp.c
index 371e72d5c..d5d497599 100644
--- a/src/lua/lua_tcp.c
+++ b/src/lua/lua_tcp.c
@@ -789,7 +789,14 @@ lua_tcp_write_helper (struct lua_tcp_cbdata *cbd)
niov = wh->iovlen;
remain = wh->pos;
/* We know that niov is small enough for that */
- cur_iov = alloca (niov * sizeof (struct iovec));
+
+ if (niov < 1024) {
+ cur_iov = g_alloca (niov * sizeof (struct iovec));
+ }
+ else {
+ cur_iov = g_malloc0 (niov * sizeof (struct iovec));
+ }
+
memcpy (cur_iov, wh->iov, niov * sizeof (struct iovec));
for (i = 0; i < wh->iovlen && remain > 0; i++) {
@@ -822,6 +829,10 @@ lua_tcp_write_helper (struct lua_tcp_cbdata *cbd)
r = sendmsg (cbd->fd, &msg, flags);
}
+ if (niov >= 1024) {
+ g_free (cur_iov);
+ }
+
if (r == -1) {
lua_tcp_push_error (cbd, FALSE, "IO write error while trying to write %d "
"bytes: %s", (gint)remain, strerror (errno));