summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2007-06-12 01:44:17 +0000
committerStef Walter <stef@memberwebs.com>2007-06-12 01:44:17 +0000
commit34d76738bd21314c56c314fe7c8cebc77b5959dc (patch)
tree38d63a07a81df314ce76c4e1c182b6b8d8f95905
parentc4a0c63f0dd25390d765b5fc52a7e91743641adf (diff)
Fix assertion when reallocating for more requests. See #211
-rw-r--r--ChangeLog3
-rw-r--r--daemon/snmp-engine.c9
2 files changed, 8 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index c3df840..9d5e436 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+0.8
+ - Fix assertion when reallocating SNMP request memory
+
0.7
- Use my real name 'Stef Walter'
See: http://memberwebs.com/nielsen/
diff --git a/daemon/snmp-engine.c b/daemon/snmp-engine.c
index 8cae2b7..e79c6c2 100644
--- a/daemon/snmp-engine.c
+++ b/daemon/snmp-engine.c
@@ -94,6 +94,7 @@ static uint nrequests = 0;
static rb_request*
new_req()
{
+ rb_request* arequests;
rb_request* req = NULL;
uint num;
int i, overlap = 0;
@@ -101,8 +102,7 @@ new_req()
if(nrequests)
{
/* We allocate in a loop starting after the last allocation. */
- for(i = (reqhigh + 1) % nrequests; i != reqhigh;
- i = (i + 1) % nrequests)
+ for(i = reqhigh; !overlap || i != reqhigh; i = (i + 1) % nrequests)
{
/*
* We can overlap past reqlow, but in that case no
@@ -134,8 +134,8 @@ new_req()
/* Reallocate the request block */
/* TODO: Once we use less memory this can be higher */
num = nrequests ? nrequests * 2 : 32;
- requests = (rb_request*)realloc(requests, sizeof(rb_request) * num);
- if(!requests)
+ arequests = (rb_request*)realloc(requests, sizeof(rb_request) * num);
+ if(!arequests)
{
/* Note we leave old requests allocated */
errno = ENOMEM;
@@ -143,6 +143,7 @@ new_req()
}
/* Clear out the new ones */
+ requests = arequests;
memset(requests + nrequests, 0, sizeof(rb_request) * (num - nrequests));
/* We return the next one */