From 12b0d76c86e1bec547d56a57bd17c4da1885b903 Mon Sep 17 00:00:00 2001 From: delphij Date: Thu, 27 Aug 2015 06:28:42 +0000 Subject: [PATCH] Plug a possible memory leak. MFC after: 2 weeks --- usr.sbin/pkg/dns_utils.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/usr.sbin/pkg/dns_utils.c b/usr.sbin/pkg/dns_utils.c index ce88048a4aad..a3c3a7e99ea2 100644 --- a/usr.sbin/pkg/dns_utils.c +++ b/usr.sbin/pkg/dns_utils.c @@ -84,7 +84,6 @@ compute_weight(struct dns_srvinfo **d, int first, int last) int i, j, totalweight; int *chosen; - chosen = malloc(sizeof(int) * (last - first + 1)); totalweight = 0; for (i = 0; i <= last; i++) @@ -93,6 +92,8 @@ compute_weight(struct dns_srvinfo **d, int first, int last) if (totalweight == 0) return; + chosen = malloc(sizeof(int) * (last - first + 1)); + for (i = 0; i <= last; i++) { for (;;) { chosen[i] = random() % (d[i]->weight * 100 / totalweight);