# ChuckCrash

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This code causes a double free fault when the first shred returns using chuck-1.2.0.5:

``` Flute flute1 => PoleZero f1 => JCRev r1 => pan2 p1 => dac;
Flute flute2 => PoleZero f2 => JCRev r2 => pan2 p2 => dac;
Flute flute3 => PoleZero f3 => JCRev r3 => pan2 p3 => dac;
Flute flute4 => PoleZero f4 => JCRev r4 => pan2 p4 => dac;
// basic play function (add more arguments as needed)
fun void play(Flute flute, float note, float velocity )
{
// start the note
std.mtof( note ) => flute.freq;
velocity => flute.noteOn;
}
// our notes
[ 61, 63, 65, 66, 68 ] @=> int notes[];
std.rand2f(0,0.56) => r1.gain;
std.rand2f(0.0,0.4) => r1.mix;
std.rand2f(0,0.56) => r2.gain;
std.rand2f(0,0.4) => r2.mix;
std.rand2f(0,0.56) => r3.gain;
std.rand2f(0,0.4) => r3.mix;
std.rand2f(0,0.56) => r4.gain;
std.rand2f(0,0.4) => r4.mix;
std.rand2(0, 1) => p1.pan;
std.rand2(0, 1) => p2.pan;
std.rand2(0, 1) => p3.pan;
std.rand2(0, 1) => p4.pan;
fun void doit (Flute flute, int maxlen, PoleZero f, JCRev r, pan2 p, int shift) {
// infinite time-loop
while( shift > 0 )
{
std.rand2f(0.0,0.5) => r.gain;
std.rand2f(0.10,0.2) => r.mix;
std.rand2f(0,1) => f1.a1;
std.rand2f(0,1) => f1.b0;
std.rand2f(0,1) => f1.b1;
std.rand2f(0,1) => f2.a1;
std.rand2f(0,1) => f2.b0;
std.rand2f(0,1) => f2.b1;
std.rand2f(0,1) => f3.a1;
std.rand2f(0,1) => f3.b0;
std.rand2f(0,1) => f3.b1;
std.rand2f(0,1) => f4.a1;
std.rand2f(0,1) => f4.b0;
std.rand2f(0,1) => f4.b1;
// set
std.rand2f(0,0.3) => flute.jetDelay;
std.rand2f(0.2, 0.5) => flute.jetReflection;
std.rand2f(0.1, 0.3) => flute.endReflection;
std.rand2f(0,0.05) => flute.noiseGain;
std.rand2f(0,5) => flute.vibratoFreq; /* 0 - 12 */
std.rand2f(0,0.2 ) => flute.vibratoGain;
std.rand2f(0.2,0.9) => flute.pressure;
// factor
std.rand2f( .75, 2 ) => float factor;
for(int i; i<std.rand2(1, 16); i++) {
std.rand2f(0.2, 0.8) => p.pan;
std.rand2(0, 50) => int note;
std.rand2f(.2, .5) => float vol;
play(flute, note, vol);
me.yield();
std.rand2f(0,maxlen)::ms * factor => now;
}
<<<shift-->>>;
}
<<<"returning">>>;
return;
}
spork ~ doit(flute1, 11600, f4, r4, p4, 1);
15000::ms => now;
spork ~ doit(flute2, 8800, f3, r3, p3, 1);
15000::ms => now;
spork ~ doit(flute3, 4400, f2, r2, p2, 1);
15000::ms => now;
spork ~ doit(flute4, 2200, f1, r1, p1, 32);
15000::ms => now;
spork ~ doit(flute4, 1600, f4, r4, p4, 37);
15000::ms => now;
spork ~ doit(flute3, 800, f3, r3, p3, 44);
15000::ms => now;
spork ~ doit(flute2, 666, f2, r2, p2, 40);
15000::ms => now;
spork ~ doit(flute1, 333, f1, r1, p1, 32);
while(true) {
1000::ms => now;
}
```
``` ~/chuck-1.2.0.5/src/chuck ~/test.chuck
0 :(int)
"returning" : (string)
16409 :(int)
"returning" : (string)
*** glibc detected *** double free or corruption (!prev): 0x083ac768 ***
```