From: nishi Date: Thu, 18 Jan 2024 11:31:39 +0000 (+0000) Subject: error handling X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=473e0c5259a75f5c8f05e4715f1c68661830ebf9;p=libw3.git error handling git-svn-id: file:///raid/svn-main/nishi-libw3/trunk@30 d27a3e52-49c5-7645-884c-6793ebffc270 --- diff --git a/Example/fetch.c b/Example/fetch.c index 5a99174..060e976 100644 --- a/Example/fetch.c +++ b/Example/fetch.c @@ -21,8 +21,14 @@ int main(int argc, char** argv){ } W3_Library_Init(); struct W3* w3 = W3_Create("http", argv[1], 80); - W3_Set_Method(w3, "GET"); - W3_Set_Path(w3, argv[2]); - W3_Send_Request(w3); - W3_Free(w3); + if(w3 != NULL){ + W3_Set_Method(w3, "GET"); + W3_Set_Path(w3, argv[2]); + W3_Send_Request(w3); + W3_Free(w3); + }else{ + fprintf(stderr, "Failed to fetch\n"); + return 1; + } + return 0; } diff --git a/Library/Core.c b/Library/Core.c index 4ce4b21..b04c10a 100644 --- a/Library/Core.c +++ b/Library/Core.c @@ -63,6 +63,10 @@ struct W3* W3_Create(const char* protocol, const char* hostname, int port){ &w3->ssl_ctx #endif ); + if(w3->sock == -1){ + W3_Free(w3); + w3 = NULL; + } return w3; } diff --git a/Library/DNS.c b/Library/DNS.c index a612569..a3b6179 100644 --- a/Library/DNS.c +++ b/Library/DNS.c @@ -51,6 +51,7 @@ int __W3_DNS_Connect(const char* hostname, bool ssl, uint16_t port sprintf(strport, "%d", port); s = getaddrinfo(hostname, strport, &hints, &result); if(s != 0){ + free(strport); __W3_Debug("Resolve", "Failed"); return -1; /* Failed to resolve */ } diff --git a/Makefile b/Makefile index bb03e3e..ede14fa 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ all: ./w3.pc ./Library/W3Version.h $(ALL) $(MAKE) -C ./Example CC=$(CC) fetch ./Library/W3Version.h: - m4 -DSUFFIX=\"/W\" ./W3Version.h.p > $@ + m4 -DSUFFIX=\"W\" ./W3Version.h.p > $@ else @@ -106,4 +106,5 @@ endif -cp LICENSE w3-$(VERSION)/ tar czvf w3-$(VERSION).tar.gz w3-$(VERSION) zip -rv w3-$(VERSION).zip w3-$(VERSION) + -/usr/lha/bin/lha a w3-$(VERSION).lzh w3-$(VERSION) rm -rf w3-$(VERSION)