From ee232ad635efe7bbef50fa5793a1d4fd0a80f92a Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 22 May 2025 12:39:53 +1000 Subject: [PATCH] Less memory leak --- src/Platform_Posix.c | 3 --- src/Resources.c | 41 ----------------------------------------- 2 files changed, 44 deletions(-) diff --git a/src/Platform_Posix.c b/src/Platform_Posix.c index 80dbe91db..80d8c1892 100644 --- a/src/Platform_Posix.c +++ b/src/Platform_Posix.c @@ -123,9 +123,6 @@ void Platform_Log(const char* msg, int len) { /* Avoid "ignoring return value of 'write' declared with attribute 'warn_unused_result'" warning */ ret = write(STDOUT_FILENO, msg, len); ret = write(STDOUT_FILENO, "\n", 1); - - cc_string str = String_Init(msg, len, len); - Logger_Log(&str); } #endif diff --git a/src/Resources.c b/src/Resources.c index 119e3f8e2..9b1b4cd63 100644 --- a/src/Resources.c +++ b/src/Resources.c @@ -64,24 +64,14 @@ static cc_result ZipEntry_ExtractData(struct ResourceZipEntry* e, struct Stream* static void ZipFile_InspectEntries(const cc_string* path, Zip_SelectEntry selector) { struct Stream stream; cc_result res; -#if CC_BUILD_MAXSTACK <= (16 * 1024) - struct ZipEntry* entries = (struct ZipEntry*)Mem_TryAllocCleared(64, sizeof(struct ZipEntry)); - if (!entries) { Logger_SysWarn2(ERR_OUT_OF_MEMORY, "allocating", path); return; } -#else struct ZipEntry entries[64]; -#endif res = Stream_OpenFile(&stream, path); if (res == ReturnCode_FileNotFound) return; if (res) { Logger_SysWarn2(res, "opening", path); return; } -#if CC_BUILD_MAXSTACK <= (16 * 1024) - res = Zip_Extract(&stream, selector, NULL, - entries, 64); -#else res = Zip_Extract(&stream, selector, NULL, entries, Array_Elems(entries)); -#endif if (res) Logger_SysWarn2(res, "inspecting", path); /* No point logging error for closing readonly file */ @@ -749,20 +739,11 @@ static cc_result CCTextures_ProcessEntry(const cc_string* path, struct Stream* d static cc_result CCTextures_ExtractZip(struct HttpRequest* req) { struct Stream src; cc_result res; -#if CC_BUILD_MAXSTACK <= (16 * 1024) - struct ZipEntry* entries = (struct ZipEntry*)Mem_TryAllocCleared(64, sizeof(struct ZipEntry)); - if (!entries) return ERR_OUT_OF_MEMORY; -#else struct ZipEntry entries[64]; -#endif Stream_ReadonlyMemory(&src, req->data, req->size); if ((res = Zip_Extract(&src, CCTextures_SelectEntry, CCTextures_ProcessEntry, -#if CC_BUILD_MAXSTACK <= (16 * 1024) - entries, 64))) return res; -#else entries, Array_Elems(entries)))) return res; -#endif return Stream_WriteAllTo(&ccTexPack, req->data, req->size); } @@ -930,25 +911,12 @@ static cc_result ClassicPatcher_ProcessEntry(const cc_string* path, struct Strea static cc_result ClassicPatcher_ExtractFiles(struct HttpRequest* req) { struct Stream src; cc_result res; -#if CC_BUILD_MAXSTACK <= (16 * 1024) - struct ZipEntry* entries = (struct ZipEntry*)Mem_TryAllocCleared(64, sizeof(struct ZipEntry)); - if (!entries) return ERR_OUT_OF_MEMORY; -#else struct ZipEntry entries[64]; -#endif Stream_ReadonlyMemory(&src, req->data, req->size); -#if CC_BUILD_MAXSTACK <= (16 * 1024) - res = Zip_Extract(&src, - ClassicPatcher_SelectEntry, ClassicPatcher_ProcessEntry, - entries, 16); - Mem_Free(entries); - return res; -#else return Zip_Extract(&src, ClassicPatcher_SelectEntry, ClassicPatcher_ProcessEntry, entries, Array_Elems(entries)); -#endif } static void PatchTerrainTile(struct Bitmap* src, int srcX, int srcY, int tileX, int tileY) { @@ -1056,21 +1024,12 @@ static cc_result ModernPatcher_ProcessEntry(const cc_string* path, struct Stream static cc_result ModernPatcher_ExtractFiles(struct HttpRequest* req) { struct Stream src; -#if CC_BUILD_MAXSTACK <= (16 * 1024) - struct ZipEntry* entries = (struct ZipEntry*)Mem_TryAllocCleared(64, sizeof(struct ZipEntry)); - if (!entries) return ERR_OUT_OF_MEMORY; -#else struct ZipEntry entries[64]; -#endif Stream_ReadonlyMemory(&src, req->data, req->size); return Zip_Extract(&src, ModernPatcher_SelectEntry, ModernPatcher_ProcessEntry, -#if CC_BUILD_MAXSTACK <= (16 * 1024) - entries, 64); -#else entries, Array_Elems(entries)); -#endif }