From 34d76738bd21314c56c314fe7c8cebc77b5959dc Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Tue, 12 Jun 2007 01:44:17 +0000 Subject: Fix assertion when reallocating for more requests. See #211 --- ChangeLog | 3 +++ daemon/snmp-engine.c | 9 +++++---- 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 */ -- cgit v1.2.3