From a40f4e080130b3724167a71b66f8da516ba548a6 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Wed, 24 Apr 2024 19:40:01 -0400 Subject: [PATCH] Start doing some C++ memory management. --- sc2/src/uqm/planets/pstarmap-modern.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sc2/src/uqm/planets/pstarmap-modern.cpp b/sc2/src/uqm/planets/pstarmap-modern.cpp index b30e96118..4033feb1d 100644 --- a/sc2/src/uqm/planets/pstarmap-modern.cpp +++ b/sc2/src/uqm/planets/pstarmap-modern.cpp @@ -16,6 +16,9 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#include + #include "../starmap.h" #include "../menustat.h" #include "../controls.h" @@ -33,7 +36,9 @@ DoStarSearch (MENU_STATE *pMS) pss = (STAR_SEARCH_STATE *) HMalloc (sizeof (*pss)); if (!pss) return FALSE; - pss->SortedStars= (int *) HMalloc( GetStarCount() * sizeof( int * ) ); + + std::vector< int > sorted( GetStarCount() ); // Manages the sorted stars memory. + pss->SortedStars= sorted.data(); if (!pss->SortedStars) { HFree (pss); @@ -64,7 +69,6 @@ DoStarSearch (MENU_STATE *pMS) DrawSISMessageEx (pss->Text, -1, -1, DSME_CLEARFR); - HFree (pss->SortedStars); HFree (pss); return success;