diff options
author | Daniel Stenberg <daniel@haxx.se> | 2019-12-19 17:17:27 +0530 |
---|---|---|
committer | Seonah Moon <seonah1.moon@samsung.com> | 2019-12-20 14:13:32 +0900 |
commit | 1930681eba52effb6534c52fdf0cd1f4c0f6554f (patch) | |
tree | a06c80a3208c66b3b080636e07e8f719a344bb82 | |
parent | babba9d0ccc8cdeb53d063fd7c1d12ba84be040d (diff) | |
download | curl-1930681eba52effb6534c52fdf0cd1f4c0f6554f.tar.gz curl-1930681eba52effb6534c52fdf0cd1f4c0f6554f.tar.bz2 curl-1930681eba52effb6534c52fdf0cd1f4c0f6554f.zip |
url: make Curl_close() NULLify the pointer too.submit/tizen_base/20191220.141841accepted/tizen/base/20191223.060023
This is the common pattern used in the code and by a unified approach we
avoid mistakes.
Backported patch details:
https://github.com/curl/curl/commit/dcd7e37c3a0ce108635b89cacc1e3425e57bd3bc
Change-Id: I453175ca40d8e8dfa7611f026ec7513dc230d16f
Signed-off-by: Niraj Kumar Goit <niraj.g@samsung.com>
-rw-r--r-- | lib/conncache.c | 8 | ||||
-rw-r--r-- | lib/doh.c | 6 | ||||
-rw-r--r-- | lib/easy.c | 2 | ||||
-rw-r--r-- | lib/http2.c | 12 | ||||
-rw-r--r-- | lib/url.c | 8 | ||||
-rw-r--r-- | lib/url.h | 2 | ||||
-rw-r--r-- | tests/unit/unit1620.c | 4 |
7 files changed, 21 insertions, 21 deletions
diff --git a/lib/conncache.c b/lib/conncache.c index d93119bed..100fec891 100644 --- a/lib/conncache.c +++ b/lib/conncache.c @@ -141,10 +141,8 @@ int Curl_conncache_init(struct conncache *connc, int size) rc = Curl_hash_init(&connc->hash, size, Curl_hash_str, Curl_str_key_compare, free_bundle_hash_entry); - if(rc) { - Curl_close(connc->closure_handle); - connc->closure_handle = NULL; - } + if(rc) + Curl_close(&connc->closure_handle); else connc->closure_handle->state.conn_cache = connc; @@ -588,7 +586,7 @@ void Curl_conncache_close_all_connections(struct conncache *connc) Curl_hostcache_clean(connc->closure_handle, connc->closure_handle->dns.hostcache); - Curl_close(connc->closure_handle); + Curl_close(&connc->closure_handle); sigpipe_restore(&pipe_st); } } @@ -256,7 +256,7 @@ static CURLcode dohprobe(struct Curl_easy *data, error: free(nurl); - Curl_close(doh); + Curl_close(&doh); return result; } @@ -831,9 +831,9 @@ CURLcode Curl_doh_is_resolved(struct connectdata *conn, struct Curl_addrinfo *ai; /* remove DOH handles from multi handle and close them */ curl_multi_remove_handle(data->multi, data->req.doh.probe[0].easy); - Curl_close(data->req.doh.probe[0].easy); + Curl_close(&data->req.doh.probe[0].easy); curl_multi_remove_handle(data->multi, data->req.doh.probe[1].easy); - Curl_close(data->req.doh.probe[1].easy); + Curl_close(&data->req.doh.probe[1].easy); /* parse the responses, create the struct and return it! */ init_dohentry(&de); diff --git a/lib/easy.c b/lib/easy.c index 2612f9590..00474be75 100644 --- a/lib/easy.c +++ b/lib/easy.c @@ -833,7 +833,7 @@ void curl_easy_cleanup(struct Curl_easy *data) return; sigpipe_ignore(data, &pipe_st); - Curl_close(data); + Curl_close(&data); sigpipe_restore(&pipe_st); } diff --git a/lib/http2.c b/lib/http2.c index 0c8b59d1a..83e88ff4f 100644 --- a/lib/http2.c +++ b/lib/http2.c @@ -505,16 +505,14 @@ static struct Curl_easy *duphandle(struct Curl_easy *data) /* setup the request struct */ struct HTTP *http = calloc(1, sizeof(struct HTTP)); if(!http) { - (void)Curl_close(second); - second = NULL; + (void)Curl_close(&second); } else { second->req.protop = http; http->header_recvbuf = Curl_add_buffer_init(); if(!http->header_recvbuf) { free(http); - (void)Curl_close(second); - second = NULL; + (void)Curl_close(&second); } else { Curl_http2_setup_req(second); @@ -556,7 +554,7 @@ static int push_promise(struct Curl_easy *data, stream = data->req.protop; if(!stream) { failf(data, "Internal NULL stream!\n"); - (void)Curl_close(newhandle); + (void)Curl_close(&newhandle); rv = 1; goto fail; } @@ -578,7 +576,7 @@ static int push_promise(struct Curl_easy *data, /* denied, kill off the new handle again */ http2_stream_free(newhandle->req.protop); newhandle->req.protop = NULL; - (void)Curl_close(newhandle); + (void)Curl_close(&newhandle); goto fail; } @@ -594,7 +592,7 @@ static int push_promise(struct Curl_easy *data, infof(data, "failed to add handle to multi\n"); http2_stream_free(newhandle->req.protop); newhandle->req.protop = NULL; - Curl_close(newhandle); + Curl_close(&newhandle); rv = 1; goto fail; } @@ -322,13 +322,17 @@ void Curl_up_free(struct Curl_easy *data) * when curl_easy_perform() is invoked. */ -CURLcode Curl_close(struct Curl_easy *data) +CURLcode Curl_close(struct Curl_easy **datap) { struct Curl_multi *m; + struct Curl_easy *data; - if(!data) + if(!datap || !*datap) return CURLE_OK; + data = *datap; + *datap = NULL; + Curl_expire_clear(data); /* shut off timers */ m = data->multi; @@ -51,7 +51,7 @@ void Curl_freeset(struct Curl_easy * data); /* free the URL pieces */ void Curl_up_free(struct Curl_easy *data); CURLcode Curl_uc_to_curlcode(CURLUcode uc); -CURLcode Curl_close(struct Curl_easy *data); /* opposite of curl_open() */ +CURLcode Curl_close(struct Curl_easy **datap); /* opposite of curl_open() */ CURLcode Curl_connect(struct Curl_easy *, struct connectdata **, bool *async, bool *protocol_connect); CURLcode Curl_disconnect(struct Curl_easy *data, diff --git a/tests/unit/unit1620.c b/tests/unit/unit1620.c index a47ff49a4..54fb21e0b 100644 --- a/tests/unit/unit1620.c +++ b/tests/unit/unit1620.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -83,7 +83,7 @@ UNITTEST_START Curl_free_request_state(empty); - rc = Curl_close(empty); + rc = Curl_close(&empty); fail_unless(rc == CURLE_OK, "Curl_close() failed"); } |