From: Michael Tremer Date: Mon, 15 Aug 2022 18:42:45 +0000 (+0000) Subject: *_unref: Always expect a valid pointer X-Git-Tag: 0.9.15~41 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=579fb6ec1116fd53dc198d9dcaa9344f6c4dc368;p=location%2Flibloc.git *_unref: Always expect a valid pointer Those functions have been very inconsistent in that way that some happily accepted a NULL pointer and others didn't. Signed-off-by: Michael Tremer --- diff --git a/src/country-list.c b/src/country-list.c index 0ed7ef1..3f4ea4e 100644 --- a/src/country-list.c +++ b/src/country-list.c @@ -81,9 +81,6 @@ static void loc_country_list_free(struct loc_country_list* list) { } LOC_EXPORT struct loc_country_list* loc_country_list_unref(struct loc_country_list* list) { - if (!list) - return NULL; - if (--list->refcount > 0) return list; diff --git a/src/libloc.c b/src/libloc.c index fb89b56..450c5e6 100644 --- a/src/libloc.c +++ b/src/libloc.c @@ -103,9 +103,6 @@ LOC_EXPORT struct loc_ctx* loc_ref(struct loc_ctx* ctx) { } LOC_EXPORT struct loc_ctx* loc_unref(struct loc_ctx* ctx) { - if (!ctx) - return NULL; - if (--ctx->refcount > 0) return NULL; diff --git a/src/network-list.c b/src/network-list.c index 9aeafb5..1b64a7e 100644 --- a/src/network-list.c +++ b/src/network-list.c @@ -83,9 +83,6 @@ static void loc_network_list_free(struct loc_network_list* list) { } LOC_EXPORT struct loc_network_list* loc_network_list_unref(struct loc_network_list* list) { - if (!list) - return NULL; - if (--list->refcount > 0) return list; diff --git a/src/network.c b/src/network.c index 12e78e7..10af51a 100644 --- a/src/network.c +++ b/src/network.c @@ -116,9 +116,6 @@ static void loc_network_free(struct loc_network* network) { } LOC_EXPORT struct loc_network* loc_network_unref(struct loc_network* network) { - if (!network) - return NULL; - if (--network->refcount > 0) return network; @@ -856,9 +853,6 @@ static void loc_network_tree_node_free(struct loc_network_tree_node* node) { } struct loc_network_tree_node* loc_network_tree_node_unref(struct loc_network_tree_node* node) { - if (!node) - return NULL; - if (--node->refcount > 0) return node; diff --git a/src/test-network.c b/src/test-network.c index 866f493..717ad3a 100644 --- a/src/test-network.c +++ b/src/test-network.c @@ -302,7 +302,6 @@ int main(int argc, char** argv) { fprintf(stderr, "Could look up 2001:db8:fffe:1::, but I shouldn't\n"); exit(EXIT_FAILURE); } - loc_network_unref(network1); const struct bit_length_test { const char* network;