Skip to content

Commit

Permalink
fix memory leak in cache manager (#677)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-m-adams authored Nov 3, 2023
1 parent 710cb29 commit f668c34
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/deluge/memory/cache_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ uint32_t CacheManager::ReclaimMemory(MemoryRegion& region, int32_t totalSizeNeed
stealable = static_cast<Stealable*>(reclamation_queue_[q].getFirst());
while (stealable != nullptr) {
// If we've already looked at this one as part of a bigger run, move on
//this works because the uint cast makes negatives high numbers instead
uint32_t lastTraversalQueue = stealable->lastTraversalNo - traversalNumberBeforeQueues;
if (lastTraversalQueue <= q) {

Expand All @@ -61,6 +62,7 @@ uint32_t CacheManager::ReclaimMemory(MemoryRegion& region, int32_t totalSizeNeed
}

// If we're forbidden from stealing from a particular thing (usually SampleCache), then make sure we don't
// TODO: this should never happen
if (!stealable->mayBeStolen(thingNotToStealFrom)) {
numRefusedTheft++;

Expand Down Expand Up @@ -113,6 +115,8 @@ uint32_t CacheManager::ReclaimMemory(MemoryRegion& region, int32_t totalSizeNeed

// If that one Stealable alone was big enough, that's great
if (amountToExtend <= 0) {
//need to reset this since it's getting stolen
longestRunSeenInThisQueue = 0xFFFFFFFF;
found = true;
break;
}
Expand All @@ -136,6 +140,10 @@ uint32_t CacheManager::ReclaimMemory(MemoryRegion& region, int32_t totalSizeNeed
stealable = static_cast<Stealable*>(reclamation_queue_[q].getNext(stealable));
continue;
}
else {
//reset this since it's getting stolen
longestRunSeenInThisQueue = 0xFFFFFFFF;
}

newSpaceAddress = result.address;

Expand All @@ -146,8 +154,10 @@ uint32_t CacheManager::ReclaimMemory(MemoryRegion& region, int32_t totalSizeNeed
break;
}

// End of that particular queue - so go to the next one
longest_runs_[q] = longestRunSeenInThisQueue;

// End of that particular queue - so go to the next one

currentTraversalNo++;
}

Expand Down
2 changes: 1 addition & 1 deletion src/deluge/model/mod_controllable/mod_controllable_audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class ModControllableAudio : public ModControllable {
static bool readParamTagFromFile(char const* tagName, ParamManagerForTimeline* paramManager,
int32_t readAutomationUpToPos);
static void initParams(ParamManager* paramManager);
void wontBeRenderedForAWhile();
virtual void wontBeRenderedForAWhile();
void endStutter(ParamManagerForTimeline* paramManager);
virtual bool setModFXType(ModFXType newType);
bool offerReceivedCCToLearnedParams(MIDIDevice* fromDevice, uint8_t channel, uint8_t ccNumber, uint8_t value,
Expand Down
2 changes: 1 addition & 1 deletion src/deluge/model/song/song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4006,7 +4006,7 @@ void Song::setHibernatingMIDIInstrument(MIDIInstrument* newInstrument) {
void Song::deleteHibernatingMIDIInstrument() {
if (hibernatingMIDIInstrument) {
void* toDealloc = dynamic_cast<void*>(hibernatingMIDIInstrument);
hibernatingMIDIInstrument->~Instrument();
hibernatingMIDIInstrument->~MIDIInstrument();
delugeDealloc(toDealloc);
hibernatingMIDIInstrument = NULL;
}
Expand Down

0 comments on commit f668c34

Please sign in to comment.