Uprising
Member
Hi
I am not sure how i can properly pass a pointer that has been allocated memory to another function and then free it.
What i am doing currently is this
I keep getting the error
***glibc detected *** double free or corruption (fasttop): 0x001fc930 ***
Aborted
However if i change the function so that it just uses the original global pointers instead of passing them to the function.
*plasmaStart;
*plasmaCurrent;
*plasmaTemp;
It works fine (atleast i think it does... :lol: ).
I am not sure how i can properly pass a pointer that has been allocated memory to another function and then free it.
What i am doing currently is this
Code:
struct bullet *plasmaStart = NULL;
struct bullet *plasmaCurrent = NULL;
struct bullet *plasmaNew = NULL;
struct bullet *plasmaTemp = NULL;
int bulletNumP = 0;
main()
{
code...
freeBullets(plasmaStart,&bulletNumP);
}
int freeBullets(struct bullet *bullet,int *bullets)
{
struct bullet *bulletPrevious;
struct bullet *bulletTemp;
struct bullet *bulletCurrent;
int x;
bulletCurrent = bulletTemp = bullet;
for(x = 0; x < *bullets; x++)
{
bulletTemp = bulletCurrent->next;
if(bulletCurrent->destroyed == 1 || bulletCurrent->framesMoved >= bulletCurrent->maxDistance)
{
if(bulletCurrent == bullet)
bullet = bulletCurrent->next;
else
bulletPrevious->next = bulletCurrent->next;
free(bulletCurrent);
*bullets = *bullets - 1;
x --;
}
else
{
bulletPrevious = bulletCurrent;
}
bulletCurrent = bulletTemp;
}
return 0;
}
I keep getting the error
***glibc detected *** double free or corruption (fasttop): 0x001fc930 ***
Aborted
However if i change the function so that it just uses the original global pointers instead of passing them to the function.
*plasmaStart;
*plasmaCurrent;
*plasmaTemp;
It works fine (atleast i think it does... :lol: ).