The code below compiles with no warnigns. Under gdb , gdb tells me it exited correctly, still it freezes my SAM440ep OS4.1.4 systematically.
???
#define __USE_INLINE__ #include <exec/types.h> #include <proto/exec.h> #include <exec/exec.h> #include <dos/dos.h> #include <proto/dos.h> #include <proto/intuition.h> #define Db(x) ; ///(x) struct GCmain { char *membuff[5]; // 5 main memory buffers of buffsize length - use them.. }*gd; int main(void) { int c; struct Remember *rkey=NULL; if (!(gd = (struct GCmain *)AllocRemember (&rkey, sizeof(struct GCmain), MEMF_CLEAR))) //// { PutStr("no gcmain obtained\n"); return 1; } for (c=0; c<5; ++c) { gd->membuff[c]=NULL; } if (!(getbuffers())) { PutStr("no buff obtained\n"); return 1; } FreeRemember(&rkey,TRUE); // free all main buffers for (c=0; c<5; ++c) { if (gd->membuff[c]) FreeVec (gd->membuff[c]); } } int getbuffers(void) { char *pt; int c; for (c=0; c<5; ++c) { if (!(pt = (char *)AllocVecTags (1024, AVT_Type, MEMF_SHARED, AVT_ClearWithValue, 0, TAG_END))) { PutStr("buffer alloc error\n"); return (0); } gd->membuff[c] = pt; } return (1); }
I would review your compiler switches, as this should give at least one warning about main() not returning any value (control reaches end of non-void function).
Try "-Wall -Werror -Wwrite-strings" for starters.
Simon
It crashes because you access the AllocRemember() allocated memory after it's been freed:
You need to change the order of the above to:
@salass00
so logic. Thanks a lot
@simon: i'll remember that one too