AllocVecTags & FreeVec

3 posts / 0 new
Last post
JosDuchIt
JosDuchIt's picture
Offline
Last seen: 2 years 11 months ago
Joined: 2012-01-08 20:57
AllocVecTags & FreeVec
Why do i get the crash indicated in the code below?
  1. #define __USE_INLINE__
  2. #include <exec/types.h>
  3. #include <proto/exec.h>
  4. #include <proto/dos.h>
  5. #include <proto/intuition.h>
  6.  
  7. int main (void)
  8. {
  9. struct ColorSpec *g_prefs = NULL; /// test
  10. PutStr("Working\n");
  11. if (!(g_prefs = (struct ColorSpec *)AllocVecTags(sizeof(struct ColorSpec),AVT_ClearWithValue, 0, TAG_DONE)))
  12. { PutStr("No Prefs obtained\n");
  13. goto endprog;
  14. }
  15.  
  16. PutStr("Gui.c Freeing prefs\n");
  17. if (g_prefs) FreeVec(&g_prefs); ///+++
  18. PutStr("Gui.c Freed prefs\n"); /// crash
  19.  
  20.  
  21. endprog:
  22. return 1;
  23.  
  24. }
salass00
salass00's picture
Offline
Last seen: 1 month 1 week ago
Joined: 2011-02-03 11:27
@JosDuchIt It crashes
@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.
JosDuchIt
JosDuchIt's picture
Offline
Last seen: 2 years 11 months ago
Joined: 2012-01-08 20:57
Thanks, I have been confused
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.
Log in or register to post comments