In this simple code should I take care about memory freeing in default case to escape from memory leak or can I use allocated memory? Does longjmp also revert memory allocations?
#include <setjmp.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, const char* argv)
{
jmp_buf jmpbuf;
int *p=NULL;
switch(setjmp(jmpbuf)){
case 0:
p=(int *) malloc(10*sizeof(int));
printf("%p\n",p);
longjmp(jmpbuf,1);
break;
default:
printf("%p\n",p);
free(p);
}
return 0;
}
No, longjmp
does not revert dynamic memory allocations.