[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ns] Bug report/fix: Memory leaks in scheduler.cc and tcp-vegas.cc
Good afternoon-
I've tracked down a couple of memory leaks. The one in Vegas probably doesn't
affect most people, but there's one in the Heap code of scheduler.cc that might
affect a lot of people- when resizing the heap the old heap memory is not freed.
Whoever switched the code from looping to a memcpy accidentally commented out
the delete of the old memory (which was bad code anyway, since it left out the
[] for an array).
----------------------------------Begin patch-----------------------------------
--- scheduler.cc.orig Tue Oct 31 13:03:47 2000
+++ scheduler.cc Tue Oct 31 13:05:18 2000
@@ -416,7 +416,7 @@
memcpy(h_elems, he_old, osize*sizeof(Heap::Heap_elem));
- //for (i = 0; i < osize; i++)
- // h_elems[i] = he_old[i];
- //delete he_old;
+ delete [] he_old;
}
i = h_size++;
-----------------------------------End patch------------------------------------
The bug in Vegas is encountered when agents are being re-used. The reset()
function clears all the variables, including the sequence number. Unfortunately,
memory is being allocated in output() based upon the value of the sequence
number- so Vegas agents will lose memory every time output is called after a
reset (e.g., every time they are re-used). Also, the destructor never freed the
memory anyway. The following patch creates a proper constructor/destructor and
fixes the reset() function.
----------------------------------Begin patch-----------------------------------
--- tcp-vegas.cc.orig Tue Oct 31 12:39:56 2000
+++ tcp-vegas.cc Tue Oct 31 13:12:20 2000
@@ -54,6 +54,16 @@
VegasTcpAgent::VegasTcpAgent() : TcpAgent()
{
+ v_sendtime_ = NULL;
+ v_transmits_ = NULL;
+}
+
+VegasTcpAgent::~VegasTcpAgent()
+{
+ if (v_sendtime_)
+ delete [] v_sendtime_;
+ if (v_transmits_)
+ delete [] v_transmits_;
}
void
@@ -100,6 +110,15 @@
v_incr_ = 0;
v_inc_flag_ = 1;
+ if (v_sendtime_) {
+ delete [] v_sendtime_;
+ v_sendtime_ = NULL;
+ }
+ if (v_transmits_) {
+ delete [] v_transmits_;
+ v_transmits_ = NULL;
+ }
+
TcpAgent::reset();
}
-----------------------------------End patch------------------------------------
Thanks,
-Eric
--------------------------------------------
Eric H. Weigle CCS-1, RADIANT team
[email protected] Los Alamos National Lab
(505) 665-4937 http://home.lanl.gov/ehw/
--------------------------------------------