mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 10:05:44 -04:00
Use HttpRequest_Free instead of directly freeing data of http request
This commit is contained in:
parent
93e1491564
commit
af18fae4f7
17
src/Entity.c
17
src/Entity.c
@ -458,15 +458,18 @@ static void Entity_CheckSkin(struct Entity* e) {
|
||||
}
|
||||
|
||||
if (!Http_GetResult(e->_skinReqID, &item)) return;
|
||||
if (!item.success) { Entity_SetSkinAll(e, true); return; }
|
||||
|
||||
Stream_ReadonlyMemory(&mem, item.data, item.size);
|
||||
if ((res = ApplySkin(e, &bmp, &mem, &skin))) {
|
||||
LogInvalidSkin(res, &skin, item.data, item.size);
|
||||
if (!item.success) {
|
||||
Entity_SetSkinAll(e, true);
|
||||
} else {
|
||||
Stream_ReadonlyMemory(&mem, item.data, item.size);
|
||||
|
||||
if ((res = ApplySkin(e, &bmp, &mem, &skin))) {
|
||||
LogInvalidSkin(res, &skin, item.data, item.size);
|
||||
}
|
||||
Mem_Free(bmp.scan0);
|
||||
}
|
||||
|
||||
Mem_Free(bmp.scan0);
|
||||
Mem_Free(item.data);
|
||||
HttpRequest_Free(&item);
|
||||
}
|
||||
|
||||
/* Returns true if no other entities are sharing this skin texture */
|
||||
|
@ -45,6 +45,9 @@ struct HttpRequest {
|
||||
struct StringsBuffer* cookies; /* Cookie list sent in requests. May be modified by the response. */
|
||||
};
|
||||
|
||||
/* Frees all dynamically allocated data from a HTTP request */
|
||||
void HttpRequest_Free(struct HttpRequest* request);
|
||||
|
||||
/* Aschronously performs a http GET request to download a skin. */
|
||||
/* If url is a skin, downloads from there. (if not, downloads from SKIN_SERVER/[skinName].png) */
|
||||
int Http_AsyncGetSkin(const cc_string* skinName, cc_uint8 flags);
|
||||
|
14
src/LWeb.c
14
src/LWeb.c
@ -215,20 +215,20 @@ static void LWebTask_Reset(struct LWebTask* task) {
|
||||
}
|
||||
|
||||
void LWebTask_Tick(struct LWebTask* task, LWebTask_ErrorCallback errorCallback) {
|
||||
struct HttpRequest req;
|
||||
struct HttpRequest item;
|
||||
if (task->completed) return;
|
||||
if (!Http_GetResult(task->reqID, &req)) return;
|
||||
if (!Http_GetResult(task->reqID, &item)) return;
|
||||
|
||||
task->working = false;
|
||||
task->completed = true;
|
||||
task->success = req.success;
|
||||
task->success = item.success;
|
||||
|
||||
if (req.success) {
|
||||
task->Handle((cc_uint8*)req.data, req.size);
|
||||
Mem_Free(req.data);
|
||||
if (item.success) {
|
||||
task->Handle(item.data, item.size);
|
||||
} else if (errorCallback) {
|
||||
errorCallback(&req);
|
||||
errorCallback(&item);
|
||||
}
|
||||
HttpRequest_Free(&item);
|
||||
}
|
||||
|
||||
void LWebTasks_Init(void) {
|
||||
|
@ -3584,7 +3584,9 @@ static void TexPackOverlay_Update(void* screen, double delta) {
|
||||
s->dirty = true;
|
||||
s->gotContent = true;
|
||||
s->contentLength = item.contentLength;
|
||||
|
||||
TexPackOverlay_UpdateLine3(s);
|
||||
HttpRequest_Free(&item);
|
||||
}
|
||||
|
||||
static void TexPackOverlay_ContextLost(void* screen) {
|
||||
|
@ -272,10 +272,9 @@ static void WoM_Reset(void) {
|
||||
static void WoM_Tick(void) {
|
||||
struct HttpRequest item;
|
||||
if (!Http_GetResult(wom_identifier, &item)) return;
|
||||
if (!item.success) return;
|
||||
|
||||
WoM_ParseConfig(&item);
|
||||
Mem_Free(item.data);
|
||||
if (item.success) WoM_ParseConfig(&item);
|
||||
HttpRequest_Free(&item);
|
||||
}
|
||||
|
||||
|
||||
|
@ -837,54 +837,55 @@ static void Fetcher_Finish(void) {
|
||||
}
|
||||
}
|
||||
|
||||
CC_NOINLINE static cc_bool Fetcher_Get(int reqID, struct HttpRequest* req) {
|
||||
if (!Http_GetResult(reqID, req)) return false;
|
||||
CC_NOINLINE static cc_bool Fetcher_Get(int reqID, struct HttpRequest* item) {
|
||||
if (!Http_GetResult(reqID, item)) return false;
|
||||
|
||||
if (req->success) {
|
||||
if (item->success) {
|
||||
Fetcher_Downloaded++;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Only show error for first failed download */
|
||||
if (!Fetcher_Failed) Fetcher_ErrorCallback(req);
|
||||
if (!Fetcher_Failed) Fetcher_ErrorCallback(item);
|
||||
Fetcher_Failed = true;
|
||||
HttpRequest_Free(item);
|
||||
|
||||
Fetcher_Finish();
|
||||
return false;
|
||||
}
|
||||
|
||||
static void Fetcher_CheckFile(struct ZipfileSource* file) {
|
||||
struct HttpRequest req;
|
||||
struct HttpRequest item;
|
||||
cc_result res;
|
||||
if (!Fetcher_Get(file->reqID, &req)) return;
|
||||
if (!Fetcher_Get(file->reqID, &item)) return;
|
||||
|
||||
file->downloaded = true;
|
||||
res = file->Process(&req);
|
||||
res = file->Process(&item);
|
||||
|
||||
if (res) {
|
||||
cc_string name = String_FromReadonly(file->name);
|
||||
Logger_SysWarn2(res, "making", &name);
|
||||
}
|
||||
Mem_Free(req.data);
|
||||
HttpRequest_Free(&item);
|
||||
|
||||
if (file->last) DefaultZip_Create();
|
||||
}
|
||||
|
||||
static void Fetcher_CheckMusic(struct MusicResource* music) {
|
||||
struct HttpRequest req;
|
||||
if (!Fetcher_Get(music->reqID, &req)) return;
|
||||
struct HttpRequest item;
|
||||
if (!Fetcher_Get(music->reqID, &item)) return;
|
||||
|
||||
music->downloaded = true;
|
||||
MusicResource_Save(music->name, &req);
|
||||
Mem_Free(req.data);
|
||||
MusicResource_Save(music->name, &item);
|
||||
HttpRequest_Free(&item);
|
||||
}
|
||||
|
||||
static void Fetcher_CheckSound(const struct SoundResource* sound) {
|
||||
struct HttpRequest req;
|
||||
if (!Fetcher_Get(sound->reqID, &req)) return;
|
||||
struct HttpRequest item;
|
||||
if (!Fetcher_Get(sound->reqID, &item)) return;
|
||||
|
||||
SoundPatcher_Save(sound->name, &req);
|
||||
Mem_Free(req.data);
|
||||
SoundPatcher_Save(sound->name, &item);
|
||||
HttpRequest_Free(&item);
|
||||
}
|
||||
|
||||
/* TODO: Implement this.. */
|
||||
|
@ -406,7 +406,6 @@ void TexturePack_CheckPending(void) {
|
||||
|
||||
if (item.success) {
|
||||
ApplyDownloaded(&item);
|
||||
Mem_Free(item.data);
|
||||
} else if (item.result) {
|
||||
Logger_Warn(item.result, "trying to download texture pack", Http_DescribeError);
|
||||
} else if (item.statusCode == 200 || item.statusCode == 304) {
|
||||
@ -420,6 +419,7 @@ void TexturePack_CheckPending(void) {
|
||||
} else {
|
||||
Chat_Add1("&c%i error when trying to download texture pack", &item.statusCode);
|
||||
}
|
||||
HttpRequest_Free(&item);
|
||||
}
|
||||
|
||||
/* Asynchronously downloads the given texture pack */
|
||||
|
@ -12,8 +12,7 @@ static cc_bool httpsOnly, httpOnly, httpsVerify;
|
||||
static char skinServer_buffer[128];
|
||||
static cc_string skinServer = String_FromArray(skinServer_buffer);
|
||||
|
||||
/* Frees data from a HTTP request. */
|
||||
static void HttpRequest_Free(struct HttpRequest* request) {
|
||||
void HttpRequest_Free(struct HttpRequest* request) {
|
||||
Mem_Free(request->data);
|
||||
request->data = NULL;
|
||||
request->size = 0;
|
||||
@ -82,7 +81,7 @@ static void RequestList_TryFree(struct RequestList* list, int id) {
|
||||
int i = RequestList_Find(list, id);
|
||||
if (i < 0) return;
|
||||
|
||||
Mem_Free(list->entries[i].data);
|
||||
HttpRequest_Free(&list->entries[i]);
|
||||
RequestList_RemoveAt(list, i);
|
||||
}
|
||||
|
||||
@ -197,7 +196,7 @@ static void Http_CleanCacheTask(struct ScheduledTask* task) {
|
||||
item = &processedReqs.entries[i];
|
||||
if (item->timeDownloaded + (10 * 1000) >= now) continue;
|
||||
|
||||
Mem_Free(item->data);
|
||||
HttpRequest_Free(item);
|
||||
RequestList_RemoveAt(&processedReqs, i);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user