Why do i get the crash indicated in the code below?
#define __USE_INLINE__ #include <exec/types.h> #include <proto/exec.h> #include <proto/dos.h> #include <proto/intuition.h> int main (void) { struct ColorSpec *g_prefs = NULL; /// test PutStr("Working\n"); if (!(g_prefs = (struct ColorSpec *)AllocVecTags(sizeof(struct ColorSpec),AVT_ClearWithValue, 0, TAG_DONE))) { PutStr("No Prefs obtained\n"); goto endprog; } PutStr("Gui.c Freeing prefs\n"); if (g_prefs) FreeVec(&g_prefs); ///+++ PutStr("Gui.c Freed prefs\n"); /// crash endprog: return 1; }
@JosDuchIt
It crashes because you are taking the address to the variable g_prefs (a pointer to the pointer) and passing it to FreeVec() instead of simply passing the pointer value as returned from AllocVecTags().
Change "FreeVec(&g_prefs);" to "FreeVec(g_prefs);" and it will work.
Thanks,
I have been confused again with pointers , but here also because the crash pointed to the next line (with addr2line) In my program this was just another FreeVec with same "&" error. I was lead to think the format was OK because no crash pointed to the first FreeVec.