Skip to content

Commit 77c9d04

Browse files
committed
Make valgrind happy again
1 parent c09fa52 commit 77c9d04

6 files changed

+53
-22
lines changed

MemoryController.cpp

+24-18
Original file line numberDiff line numberDiff line change
@@ -511,16 +511,6 @@ void MemoryController::update()
511511
PRINT(" Col : " << newTransactionColumn);
512512
}
513513

514-
// If we have a read, save the transaction so when the data comes back
515-
// in a bus packet, we can staple it back into a transaction and return it
516-
if (transaction->transactionType == DATA_READ)
517-
{
518-
pendingReadTransactions.push_back(transaction);
519-
}
520-
else
521-
{
522-
//the transaction has been turned into a buspacket, so we don't need it anymore
523-
}
524514

525515

526516
//now that we know there is room in the command queue, we can remove from the transaction queue
@@ -538,20 +528,26 @@ void MemoryController::update()
538528
newTransactionBank, transaction->data, dramsim_log);
539529

540530

541-
/* only allow one transaction to be scheduled per cycle -- this should
542-
* be a reasonable assumption considering how much logic would be
543-
* required to schedule multiple entries per cycle (parallel data
544-
* lines, switching logic, decision logic)
545-
*/
531+
546532
commandQueue.enqueue(ACTcommand);
547533
commandQueue.enqueue(command);
548534

549-
// if the transaction isn't a read, we don't need to keep it around anymore
550-
if (transaction->transactionType != DATA_READ)
535+
// If we have a read, save the transaction so when the data comes back
536+
// in a bus packet, we can staple it back into a transaction and return it
537+
if (transaction->transactionType == DATA_READ)
538+
{
539+
pendingReadTransactions.push_back(transaction);
540+
}
541+
else
551542
{
543+
// just delete the transaction now that it's a buspacket
552544
delete transaction;
553545
}
554-
546+
/* only allow one transaction to be scheduled per cycle -- this should
547+
* be a reasonable assumption considering how much logic would be
548+
* required to schedule multiple entries per cycle (parallel data
549+
* lines, switching logic, decision logic)
550+
*/
555551
break;
556552
}
557553
else // no room, do nothing this cycle
@@ -687,6 +683,7 @@ void MemoryController::update()
687683
ERROR("Can't find a matching transaction for 0x"<<hex<<returnTransaction[0]->address<<dec);
688684
abort();
689685
}
686+
delete returnTransaction[0];
690687
returnTransaction.erase(returnTransaction.begin());
691688
}
692689

@@ -962,6 +959,15 @@ MemoryController::~MemoryController()
962959
{
963960
//ERROR("MEMORY CONTROLLER DESTRUCTOR");
964961
//abort();
962+
for (size_t i=0; i<pendingReadTransactions.size(); i++)
963+
{
964+
delete pendingReadTransactions[i];
965+
}
966+
for (size_t i=0; i<returnTransaction.size(); i++)
967+
{
968+
delete returnTransaction[i];
969+
}
970+
965971
}
966972
//inserts a latency into the latency histogram
967973
void MemoryController::insertHistogram(unsigned latencyValue, unsigned rank, unsigned bank)

MemorySystem.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ MemorySystem::MemorySystem(unsigned id, unsigned int megsOfMemory, ofstream &vis
141141
ranks->push_back(r);
142142
}
143143

144-
145144
memoryController->attachRanks(ranks);
146145

147146
}
@@ -155,6 +154,11 @@ MemorySystem::~MemorySystem()
155154
// abort();
156155

157156
delete(memoryController);
157+
158+
for (size_t i=0; i<NUM_RANKS; i++)
159+
{
160+
delete (*ranks)[i];
161+
}
158162
ranks->clear();
159163
delete(ranks);
160164

MultiChannelMemorySystem.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,13 @@ void MultiChannelMemorySystem::mkdirIfNotExist(string path)
338338

339339
MultiChannelMemorySystem::~MultiChannelMemorySystem()
340340
{
341-
// Should only ever be called on exit, so don't bother to delete stuff, just
342-
// flush our streams and close em up
341+
for (size_t i=0; i<NUM_CHANS; i++)
342+
{
343+
delete channels[i];
344+
}
345+
channels.clear();
346+
347+
// flush our streams and close them up
343348
#ifdef LOG_OUTPUT
344349
dramsim_log.flush();
345350
dramsim_log.close();

Rank.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,15 @@ void Rank::attachMemoryController(MemoryController *memoryController)
7070
{
7171
this->memoryController = memoryController;
7272
}
73-
73+
Rank::~Rank()
74+
{
75+
for (size_t i=0; i<readReturnPacket.size(); i++)
76+
{
77+
delete readReturnPacket[i];
78+
}
79+
readReturnPacket.clear();
80+
delete outgoingDataPacket;
81+
}
7482
void Rank::receiveFromBus(BusPacket *packet)
7583
{
7684
if (DEBUG_BUS)

Rank.h

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class Rank : public SimulatorObject
5959
public:
6060
//functions
6161
Rank(ostream &dramsim_log_);
62+
virtual ~Rank();
6263
void receiveFromBus(BusPacket *packet);
6364
void attachMemoryController(MemoryController *mc);
6465
int getId() const;

TraceBasedSim.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,8 @@ int main(int argc, char **argv)
564564
#ifdef RETURN_TRANSACTIONS
565565
transactionReceiver.add_pending(trans, i);
566566
#endif
567+
// the memory system accepted our request so now it takes ownership of it
568+
trans = NULL;
567569
}
568570
}
569571
else
@@ -592,6 +594,7 @@ int main(int argc, char **argv)
592594
#ifdef RETURN_TRANSACTIONS
593595
transactionReceiver.add_pending(trans, i);
594596
#endif
597+
trans=NULL;
595598
}
596599
}
597600

@@ -601,6 +604,10 @@ int main(int argc, char **argv)
601604
traceFile.close();
602605
(*memorySystem).printStats();
603606
// make valgrind happy
607+
if (trans)
608+
{
609+
delete trans;
610+
}
604611
delete(memorySystem);
605612
}
606613
#endif

0 commit comments

Comments
 (0)