From 2a572aab21b2605d9935bee72d7ed275c57bd417 Mon Sep 17 00:00:00 2001 From: Davide Beatrici Date: Sun, 30 Dec 2018 14:46:26 +0100 Subject: [PATCH] Mayaqua: fix segmentation fault, add new FreeHttpHeaderSafe() function --- src/Mayaqua/Network.c | 9 ++++++++- src/Mayaqua/Network.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Mayaqua/Network.c b/src/Mayaqua/Network.c index f8628ea0..bfe7212b 100644 --- a/src/Mayaqua/Network.c +++ b/src/Mayaqua/Network.c @@ -20645,7 +20645,7 @@ HTTP_HEADER *RecvHttpHeader(SOCK *s) if (AddHttpValueStr(header, str) == false) { FreeSafe(PTR_TO_PTR(str)); - FreeHttpHeader(header); + FreeHttpHeaderSafe(&header); break; } @@ -20900,6 +20900,13 @@ void FreeHttpHeader(HTTP_HEADER *header) Free(header); } +// Release the HTTP header and set pointer's value to NULL +void FreeHttpHeaderSafe(HTTP_HEADER **header) +{ + FreeHttpHeader(*header); + *header = NULL; +} + // Receive a PACK PACK *RecvPack(SOCK *s) { diff --git a/src/Mayaqua/Network.h b/src/Mayaqua/Network.h index 66458c49..bfe1caf4 100644 --- a/src/Mayaqua/Network.h +++ b/src/Mayaqua/Network.h @@ -1037,6 +1037,7 @@ HTTP_HEADER *NewHttpHeaderEx(char *method, char *target, char *version, bool no_ int CompareHttpValue(void *p1, void *p2); void FreeHttpValue(HTTP_VALUE *value); void FreeHttpHeader(HTTP_HEADER *header); +void FreeHttpHeaderSafe(HTTP_HEADER **header); bool SendPack(SOCK *s, PACK *p); PACK *RecvPack(SOCK *s);