mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2026-01-31 02:14:09 +03:00
Replace all free calls with VVV_free[func]
This replaces all calls to SDL_free with a new macro, VVV_free, that nulls the pointer afterwards. This mitigates any use-after-frees and also completely eliminates double-frees. The same is done for any function to free specific objects such as SDL_FreeSurface, with the VVV_freefunc macro. No exceptions for any of these calls, even if the pointer is discarded or zeroed afterwards anyway. Better safe than sorry. This is a macro rather than a function that takes in a pointer-to-pointer because such a function would have type issues that require casting and that's just not safe. Even though SDL_free and other SDL functions already check for NULL, the macro has a NULL check for other functions that don't. For example, FAudioVoice_DestroyVoice does not check for NULL. FILESYSTEM_freeMemory has been axed in favor of VVV_free because it functionally does the same thing except for `unsigned char*` only.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "Alloc.h"
|
||||
#include "Graphics.h"
|
||||
#include "Maths.h"
|
||||
|
||||
@@ -226,7 +227,7 @@ void BlitSurfaceColoured(
|
||||
}
|
||||
|
||||
SDL_BlitSurface(tempsurface, _srcRect, _dest, tempRect);
|
||||
SDL_FreeSurface(tempsurface);
|
||||
VVV_freefunc(SDL_FreeSurface, tempsurface);
|
||||
}
|
||||
|
||||
void BlitSurfaceTinted(
|
||||
@@ -287,7 +288,7 @@ void BlitSurfaceTinted(
|
||||
}
|
||||
|
||||
SDL_BlitSurface(tempsurface, _srcRect, _dest, tempRect);
|
||||
SDL_FreeSurface(tempsurface);
|
||||
VVV_freefunc(SDL_FreeSurface, tempsurface);
|
||||
}
|
||||
|
||||
|
||||
@@ -489,7 +490,7 @@ void ScrollSurface( SDL_Surface* _src, int _pX, int _pY )
|
||||
//Cleanup temp surface
|
||||
if (part1)
|
||||
{
|
||||
SDL_FreeSurface(part1);
|
||||
VVV_freefunc(SDL_FreeSurface, part1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user