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);