Less memory leak

This commit is contained in:
UnknownShadow200 2025-05-22 12:39:53 +10:00
parent 603ac3218c
commit ee232ad635
2 changed files with 0 additions and 44 deletions

View File

@ -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

View File

@ -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
}