@@ -1526,12 +1526,16 @@ void Faust_next_clear(Faust* unit, int inNumSamples)
15261526
15271527void Faust_Ctor (Faust* unit) // module constructor
15281528{
1529+ // init such that we can still free them in the destructor if
1530+ // allocation fails.
1531+ unit->mDSP = nullptr ;
1532+ unit->mInBufCopy = nullptr ;
1533+ unit->mInBufValue = nullptr ;
1534+
15291535 // allocate dsp
1530- unit->mDSP = new (RTAlloc (unit->mWorld , sizeof (FAUSTCLASS))) FAUSTCLASS ();
1531- if (!unit->mDSP ) {
1532- Print (" Faust[%s]: RT memory allocation failed, try increasing the real-time memory size in the server options\n " , g_unitName);
1533- goto end;
1534- }
1536+ void * mem = RTAlloc (unit->mWorld , sizeof (FAUSTCLASS));
1537+ ClearUnitIfMemFailed (mem);
1538+ unit->mDSP = new (mem) FAUSTCLASS ();
15351539 {
15361540 // init dsp
15371541 unit->mDSP ->instanceInit ((int )SAMPLERATE);
@@ -1561,24 +1565,15 @@ void Faust_Ctor(Faust* unit) // module constructor
15611565 SETCALC (Faust_next);
15621566 } else {
15631567 unit->mInBufCopy = (float **)RTAlloc (unit->mWorld , unit->getNumAudioInputs ()*sizeof (float *));
1564- if (!unit->mInBufCopy ) {
1565- Print (" Faust[%s]: RT memory allocation failed, try increasing the real-time memory size in the server options\n " , g_unitName);
1566- goto end;
1567- }
1568+ ClearUnitIfMemFailed (unit->mInBufCopy );
15681569 // Allocate memory for input buffer copies (numInputs * bufLength)
15691570 // and linear interpolation state (numInputs)
15701571 // = numInputs * (bufLength + 1)
15711572 unit->mInBufValue = (float *)RTAlloc (unit->mWorld , unit->getNumAudioInputs ()*sizeof (float ));
1572- if (!unit->mInBufValue ) {
1573- Print (" Faust[%s]: RT memory allocation failed, try increasing the real-time memory size in the server options\n " , g_unitName);
1574- goto end;
1575- }
1573+ ClearUnitIfMemFailed (unit->mInBufValue );
15761574 // Aquire memory for interpolator state.
1577- float * mem = (float *)RTAlloc (unit->mWorld , unit->getNumAudioInputs ()*BUFLENGTH*sizeof (float ));
1578- if (mem) {
1579- Print (" Faust[%s]: RT memory allocation failed, try increasing the real-time memory size in the server options\n " , g_unitName);
1580- goto end;
1581- }
1575+ auto * mem = (float *)RTAlloc (unit->mWorld , unit->getNumAudioInputs ()*BUFLENGTH*sizeof (float ));
1576+ ClearUnitIfMemFailed (mem);
15821577 for (int i = 0 ; i < unit->getNumAudioInputs (); ++i) {
15831578 // Initialize interpolator.
15841579 unit->mInBufValue [i] = IN0 (i);
@@ -1608,7 +1603,6 @@ void Faust_Ctor(Faust* unit) // module constructor
16081603 }
16091604 }
16101605
1611- end:
16121606 // Fix for https://github.com/grame-cncm/faust/issues/13
16131607 ClearUnitOutputs (unit, 1 );
16141608}
0 commit comments