I know that I should set the pointer tu NULL, but I don't see any reason why to do that before removing the BMAP.

Take a look at the code I posted:

Code:
if(pan->bmap != NULL) { 
bmap_purge(pan->bmap); 
ptr_remove(pan->bmap); 
pan->bmap = NULL; }



As you can see I set the bmap pointer to NULL AFTER removing the bmap.
If I call "pan->bmap = NULL;" before I couldn't call "bmap_purge(pan->bmap)" afterwards because "pan->bmap" points to NULL.