Skip to content

Commit d751fbc

Browse files
committed
dns_cache: fix cache memory size issue.
1 parent 9de809a commit d751fbc

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/dns_cache.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ static int _dns_cache_read_record(int fd, uint32_t cache_number, dns_cache_read_
674674
{
675675
unsigned int i = 0;
676676
ssize_t ret = 0;
677+
int data_size = 0;
677678
struct dns_cache_record cache_record;
678679
struct dns_cache_data_head data_head;
679680
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_
706707
goto errout;
707708
}
708709

709-
cache_data = malloc(data_head.size + sizeof(data_head));
710+
data_size = data_head.size + sizeof(data_head);
711+
cache_data = malloc(data_size);
710712
if (cache_data == NULL) {
711713
tlog(TLOG_ERROR, "malloc cache data failed %s", strerror(errno));
712714
goto errout;
@@ -724,6 +726,7 @@ static int _dns_cache_read_record(int fd, uint32_t cache_number, dns_cache_read_
724726
cache_record.info.is_visited = 0;
725727
cache_record.info.domain[DNS_MAX_CNAME_LEN - 1] = '\0';
726728
cache_record.info.dns_group_name[DNS_GROUP_NAME_LEN - 1] = '\0';
729+
atomic_add(data_size, &dns_cache_head.mem_size);
727730
ret = callback(&cache_record, cache_data);
728731
dns_cache_data_put(cache_data);
729732
cache_data = NULL;

0 commit comments

Comments
 (0)