MemLeak: fix memory leak when cache size is 0
This commit is contained in:
@@ -298,6 +298,7 @@ int dns_cache_insert(char *domain, int ttl, dns_type_t qtype, int speed, struct
|
||||
}
|
||||
|
||||
if (dns_cache_head.size <= 0) {
|
||||
dns_cache_data_free(cache_data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1718,19 +1718,19 @@ static int _DNS_client_create_socket_tls(struct dns_server_info *server_info, ch
|
||||
const int ip_tos = SOCKET_IP_TOS;
|
||||
|
||||
if (server_info->ssl_ctx == NULL) {
|
||||
tlog(TLOG_ERROR, "create ssl ctx failed.");
|
||||
tlog(TLOG_ERROR, "create ssl ctx failed, %s", server_info->ip);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
ssl = SSL_new(server_info->ssl_ctx);
|
||||
if (ssl == NULL) {
|
||||
tlog(TLOG_ERROR, "new ssl failed.");
|
||||
tlog(TLOG_ERROR, "new ssl failed, %s", server_info->ip);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
fd = socket(server_info->ai_family, SOCK_STREAM, 0);
|
||||
if (fd < 0) {
|
||||
tlog(TLOG_ERROR, "create socket failed.");
|
||||
tlog(TLOG_ERROR, "create socket failed, %s", strerror(errno));
|
||||
goto errout;
|
||||
}
|
||||
|
||||
|
||||
@@ -839,6 +839,7 @@ static int _dns_server_request_complete_AAAA(struct dns_request *request)
|
||||
if (_dns_server_request_update_cache(request, DNS_T_AAAA, cache_data) != 0) {
|
||||
goto errout;
|
||||
}
|
||||
cache_data = NULL;
|
||||
}
|
||||
|
||||
request->has_soa = 0;
|
||||
@@ -862,6 +863,7 @@ static int _dns_server_request_complete_AAAA(struct dns_request *request)
|
||||
if (_dns_server_request_update_cache(request, DNS_T_A, cache_data) != 0) {
|
||||
goto errout;
|
||||
}
|
||||
cache_data = NULL;
|
||||
}
|
||||
|
||||
if (request->dualstack_selection) {
|
||||
@@ -881,7 +883,7 @@ static int _dns_server_request_complete_AAAA(struct dns_request *request)
|
||||
return 0;
|
||||
|
||||
errout:
|
||||
if (cache_data == NULL) {
|
||||
if (cache_data != NULL) {
|
||||
dns_cache_data_free(cache_data);
|
||||
cache_data = NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user