save_stack() called without calling restore_stack()
This looks like a bug to me. fractalb.c, ComplexPower_bf: _BFCMPLX *ComplexPower_bf(_BFCMPLX *t, _BFCMPLX *xx, _BFCMPLX *yy) { _BFCMPLX tmp; bf_t e2x, siny, cosy; int saved; saved = save_stack(); e2x = alloc_stack(rbflength+2); siny = alloc_stack(rbflength+2); cosy = alloc_stack(rbflength+2); tmp.x = alloc_stack(rbflength+2); tmp.y = alloc_stack(rbflength+2); /* 0 raised to anything is 0 */ if (is_bf_zero(xx->x) && is_bf_zero(xx->y)) { clear_bf(t->x); clear_bf(t->y); return(t); } cmplxlog_bf(t, xx); cplxmul_bf(&tmp, t, yy); exp_bf(e2x,tmp.x); sincos_bf(siny,cosy,tmp.y); mult_bf(t->x, e2x, cosy); mult_bf(t->y, e2x, siny); restore_stack(saved); return(t); } When the 'if' is taken above, restore_stack() is not called and bignum memory stack is leaked. This structure is repeated again in ComplexPower_bn. -- "The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download <http://www.xmission.com/~legalize/book/download/index.html> Legalize Adulthood! <http://blogs.xmission.com/legalize/>
Rich wrote:
This looks like a bug to me.
Yup, good catch. We should either add restore_stack(saved); before the return, though I'd prefer and else clause so there's one return at the bottom with the restore_stack. I was going to say use a goto, but the else is so easy there's no excuse for a goto :-) Thanks, Tim
I have fixed the fractalb.c stack bug Rich found in two places and committed to the subversion trunk. This is dangerous because I'm not currently set up to compile and test, but I think what I did is OK (knock on wood). I'll test it as soon as I can. I've got a retreat this weekend and a visit to first grandkid next weekend. Tim
participants (2)
-
Richard -
Tim Wegner