From 4a9ebf1460d9baf26ab748938cd4e11b2109b7b5 Mon Sep 17 00:00:00 2001 From: Vladimir Olteanu Date: Sun, 5 Sep 2021 00:46:41 +0300 Subject: [PATCH] Use SDLUniquePtr --- Source/dx.cpp | 7 ++----- Source/utils/paths.cpp | 6 +++--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Source/dx.cpp b/Source/dx.cpp index 3819fef76..05ad69d2e 100644 --- a/Source/dx.cpp +++ b/Source/dx.cpp @@ -297,12 +297,9 @@ void Blit(SDL_Surface *src, SDL_Rect *srcRect, SDL_Rect *dstRect) // A surface with a non-output pixel format but without a color key needs scaling. // We can convert the format and then call BlitScaled. - SDL_Surface *converted = SDL_ConvertSurface(src, dst->format, 0); - if (SDL_BlitScaled(converted, srcRect, dst, dstRect) < 0) { - SDL_FreeSurface(converted); + SDLSurfaceUniquePtr converted = SDLWrap::ConvertSurface(src, dst->format, 0); + if (SDL_BlitScaled(converted.get(), srcRect, dst, dstRect) < 0) ErrSdl(); - } - SDL_FreeSurface(converted); #endif } diff --git a/Source/utils/paths.cpp b/Source/utils/paths.cpp index e060e3cb8..8f353288d 100644 --- a/Source/utils/paths.cpp +++ b/Source/utils/paths.cpp @@ -5,6 +5,7 @@ #include "utils/file_util.h" #include "utils/log.hpp" #include "utils/stdcompat/optional.hpp" +#include "utils/sdl_ptrs.h" #ifdef USE_SDL1 #include "utils/sdl2_to_1_2_backports.h" @@ -48,10 +49,9 @@ void AddTrailingSlash(std::string &path) std::string FromSDL(char *s) { + SDLUniquePtr pinned(s); std::string result = (s != nullptr ? s : ""); - if (s != nullptr) { - SDL_free(s); - } else { + if (s == nullptr) { Log("{}", SDL_GetError()); SDL_ClearError(); }