A couple of tips I've learned that may be able to help:
1. After free; you can set your pointer to NULL:
screen = NULL;
And so I suggest for every free to set the pointer to NULL. Because should you call free again on the same pointer, free(NULL) won't crash! See the C standard 188.8.131.52: http://www.open-std.org/JTC1/SC22/wg14/www/docs/n1124.pdf
But that may be an indication that you are freeing the same memory twice.
2. Are you using an emulator or only transferring to your calculator? I only say because if you use an emulator; besides being faster you can add printf (amongst other things) to see the values of variables:
printf("Screen pointer is at address %p\n", screen);
3. Are you using anything for the graphics? That is entirely your choice; but nRGBLib (http://ourl.ca/14731
) is really helpful! In there is a macro:
#define GetNewScreenBuffer() malloc(SCREEN_BYTES_SIZE)
And I am thinking you could use that instead of writing it yourself.
If you post your source code I'll take a look to see why the calculator reboots on exit. I've chased down a few of these now!
Have a great day!