Sfoglia il codice sorgente

dns_cache: fix cache memory size issue.

Nick Peng 6 mesi fa
parent
commit
d751fbc73f
1 ha cambiato i file con 4 aggiunte e 1 eliminazioni
  1. 4 1
      src/dns_cache.c

+ 4 - 1
src/dns_cache.c

@@ -674,6 +674,7 @@ static int _dns_cache_read_record(int fd, uint32_t cache_number, dns_cache_read_
 {
 	unsigned int i = 0;
 	ssize_t ret = 0;
+	int data_size = 0;
 	struct dns_cache_record cache_record;
 	struct dns_cache_data_head data_head;
 	struct dns_cache_data *cache_data = NULL;
@@ -706,7 +707,8 @@ static int _dns_cache_read_record(int fd, uint32_t cache_number, dns_cache_read_
 			goto errout;
 		}
 
-		cache_data = malloc(data_head.size + sizeof(data_head));
+		data_size = data_head.size + sizeof(data_head);
+		cache_data = malloc(data_size);
 		if (cache_data == NULL) {
 			tlog(TLOG_ERROR, "malloc cache data failed %s", strerror(errno));
 			goto errout;
@@ -724,6 +726,7 @@ static int _dns_cache_read_record(int fd, uint32_t cache_number, dns_cache_read_
 		cache_record.info.is_visited = 0;
 		cache_record.info.domain[DNS_MAX_CNAME_LEN - 1] = '\0';
 		cache_record.info.dns_group_name[DNS_GROUP_NAME_LEN - 1] = '\0';
+		atomic_add(data_size, &dns_cache_head.mem_size);
 		ret = callback(&cache_record, cache_data);
 		dns_cache_data_put(cache_data);
 		cache_data = NULL;