mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-10 07:49:57 -04:00
Less memory leak
This commit is contained in:
parent
603ac3218c
commit
ee232ad635
@ -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 */
|
/* Avoid "ignoring return value of 'write' declared with attribute 'warn_unused_result'" warning */
|
||||||
ret = write(STDOUT_FILENO, msg, len);
|
ret = write(STDOUT_FILENO, msg, len);
|
||||||
ret = write(STDOUT_FILENO, "\n", 1);
|
ret = write(STDOUT_FILENO, "\n", 1);
|
||||||
|
|
||||||
cc_string str = String_Init(msg, len, len);
|
|
||||||
Logger_Log(&str);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -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) {
|
static void ZipFile_InspectEntries(const cc_string* path, Zip_SelectEntry selector) {
|
||||||
struct Stream stream;
|
struct Stream stream;
|
||||||
cc_result res;
|
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];
|
struct ZipEntry entries[64];
|
||||||
#endif
|
|
||||||
|
|
||||||
res = Stream_OpenFile(&stream, path);
|
res = Stream_OpenFile(&stream, path);
|
||||||
if (res == ReturnCode_FileNotFound) return;
|
if (res == ReturnCode_FileNotFound) return;
|
||||||
if (res) { Logger_SysWarn2(res, "opening", path); 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,
|
res = Zip_Extract(&stream, selector, NULL,
|
||||||
entries, Array_Elems(entries));
|
entries, Array_Elems(entries));
|
||||||
#endif
|
|
||||||
if (res) Logger_SysWarn2(res, "inspecting", path);
|
if (res) Logger_SysWarn2(res, "inspecting", path);
|
||||||
|
|
||||||
/* No point logging error for closing readonly file */
|
/* 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) {
|
static cc_result CCTextures_ExtractZip(struct HttpRequest* req) {
|
||||||
struct Stream src;
|
struct Stream src;
|
||||||
cc_result res;
|
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];
|
struct ZipEntry entries[64];
|
||||||
#endif
|
|
||||||
|
|
||||||
Stream_ReadonlyMemory(&src, req->data, req->size);
|
Stream_ReadonlyMemory(&src, req->data, req->size);
|
||||||
if ((res = Zip_Extract(&src, CCTextures_SelectEntry, CCTextures_ProcessEntry,
|
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;
|
entries, Array_Elems(entries)))) return res;
|
||||||
#endif
|
|
||||||
|
|
||||||
return Stream_WriteAllTo(&ccTexPack, req->data, req->size);
|
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) {
|
static cc_result ClassicPatcher_ExtractFiles(struct HttpRequest* req) {
|
||||||
struct Stream src;
|
struct Stream src;
|
||||||
cc_result res;
|
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];
|
struct ZipEntry entries[64];
|
||||||
#endif
|
|
||||||
Stream_ReadonlyMemory(&src, req->data, req->size);
|
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,
|
return Zip_Extract(&src,
|
||||||
ClassicPatcher_SelectEntry, ClassicPatcher_ProcessEntry,
|
ClassicPatcher_SelectEntry, ClassicPatcher_ProcessEntry,
|
||||||
entries, Array_Elems(entries));
|
entries, Array_Elems(entries));
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PatchTerrainTile(struct Bitmap* src, int srcX, int srcY, int tileX, int tileY) {
|
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) {
|
static cc_result ModernPatcher_ExtractFiles(struct HttpRequest* req) {
|
||||||
struct Stream src;
|
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];
|
struct ZipEntry entries[64];
|
||||||
#endif
|
|
||||||
Stream_ReadonlyMemory(&src, req->data, req->size);
|
Stream_ReadonlyMemory(&src, req->data, req->size);
|
||||||
|
|
||||||
return Zip_Extract(&src,
|
return Zip_Extract(&src,
|
||||||
ModernPatcher_SelectEntry, ModernPatcher_ProcessEntry,
|
ModernPatcher_SelectEntry, ModernPatcher_ProcessEntry,
|
||||||
#if CC_BUILD_MAXSTACK <= (16 * 1024)
|
|
||||||
entries, 64);
|
|
||||||
#else
|
|
||||||
entries, Array_Elems(entries));
|
entries, Array_Elems(entries));
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user