From: Oleksandr Natalenko <oleksandr@natalenko.name>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH 2/2] segtree: allocate memory for arrays on heap
Date: Mon, 2 Jan 2017 18:38:51 +0100 [thread overview]
Message-ID: <20170102173851.2542-3-oleksandr@natalenko.name> (raw)
In-Reply-To: <20170102173851.2542-1-oleksandr@natalenko.name>
Huge sets may cause stack to be exhausted.
So, put allocate memory for arrays in
interval_map_decompose() function on heap.
Signed-off-by: Oleksandr Natalenko <oleksandr@natalenko.name>
---
src/segtree.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/segtree.c b/src/segtree.c
index 5b6cdd1..d3873d9 100644
--- a/src/segtree.c
+++ b/src/segtree.c
@@ -608,12 +608,15 @@ static int expr_value_cmp(const void *p1, const void *p2)
void interval_map_decompose(struct expr *set)
{
- struct expr *elements[set->size], *ranges[set->size * 2];
+ struct expr **elements, **ranges;
struct expr *i, *next, *low = NULL, *end;
unsigned int n, m, size;
mpz_t range, p;
bool interval;
+ elements = xmalloc_array(set->size, sizeof(struct expr *));
+ ranges = xmalloc_array(set->size * 2, sizeof(struct expr *));
+
mpz_init(range);
mpz_init(p);
@@ -728,4 +731,7 @@ void interval_map_decompose(struct expr *set)
compound_expr_add(set, i);
}
+
+ xfree(ranges);
+ xfree(elements);
}
--
2.11.0
prev parent reply other threads:[~2017-01-02 17:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-02 17:38 [PATCH 0/2] segtree: move huge arrays to heap Oleksandr Natalenko
2017-01-02 17:38 ` [PATCH 1/2] utils: provide array allocation wrapper Oleksandr Natalenko
2017-01-02 17:38 ` Oleksandr Natalenko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170102173851.2542-3-oleksandr@natalenko.name \
--to=oleksandr@natalenko.name \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).