Bug 118

Summary: Orphaned pointers when setting maximum voices limit
Product: LinuxSampler Reporter: Grigor Iliev <gr.iliev>
Component: gig::EngineAssignee: Christian Schoenebeck <cuse>
Status: CLOSED FIXED    
Severity: critical CC: andreas56
Priority: P2    
Version: SVN Trunk   
Hardware: All   
OS: All   
Attachments: 118.patch.bz2

Description Grigor Iliev 2009-02-12 14:26:14 CET
When setting the maximum voices limit Engine::pDimRegionPool[0] and Engine::pDimRegionPool[1]  are 
deleted (engines/gig/Engine.cpp:2134) but if there are already sampler channels connected to audio 
devices they continue to use the pointers to the memory now freed (pDimRegionsInUse uses the freed 
pools - engines/gig/EngineChannel.cpp:298)
Comment 1 Grigor Iliev 2009-02-18 15:27:08 CET
Attached patch.

Note: to reproduce this bug load instrument to a sampler channel, change the
maximum voice limit and start playing notes.
Comment 2 Grigor Iliev 2009-02-18 15:29:30 CET
Created attachment 47 [details]
118.patch.bz2
Comment 3 Andreas Persson 2009-02-21 14:42:39 CET
The patch works fine for me, but I think the ClearDimRegionsInUse part is
unnecessary.
Comment 4 Grigor Iliev 2009-02-21 17:37:50 CET
(In reply to comment #3)
> The patch works fine for me, but I think the ClearDimRegionsInUse part is
> unnecessary.

If you set the maximum voice limit while there are active streams
pDimRegionsInUse will not be empty and, if you delete pDimRegionPool before
clearing/deleting pDimRegionsInUse, in its destructor pDimRegionsInUse will try
to push back the elements in the list to pDimRegionPool, which is already
deleted. So in this case a memory corruption will occur.
See bug #120 before testing this scenario.
Comment 5 Andreas Persson 2009-02-21 17:53:37 CET
(In reply to comment #4)
Ah, you're right of course. This is the part I missed when I looked at the code
before:

> its destructor pDimRegionsInUse will try
> to push back the elements in the list to pDimRegionPool
Comment 6 Grigor Iliev 2009-02-21 18:11:57 CET
Applied the patch.