Free memory when it is no more used
Memory leak happen when Android data framework updates identical DNS
information to netd.
Bug: 115595601
Test: netd_unit_test, netd_integration_test
Change-Id: Idcc0956729286563603f482258f488a1ccd75e6a
diff --git a/libc/dns/resolv/res_cache.c b/libc/dns/resolv/res_cache.c
index dda8694..8de9643 100644
--- a/libc/dns/resolv/res_cache.c
+++ b/libc/dns/resolv/res_cache.c
@@ -2067,14 +2067,19 @@
// max_samples actually change, in practice the overhead of checking is higher than the
// cost, and overflows are unlikely
++cache_info->revision_id;
- } else if (cache_info->params.max_samples != old_max_samples) {
- // If the maximum number of samples changes, the overhead of keeping the most recent
- // samples around is not considered worth the effort, so they are cleared instead. All
- // other parameters do not affect shared state: Changing these parameters does not
- // invalidate the samples, as they only affect aggregation and the conditions under
- // which servers are considered usable.
- _res_cache_clear_stats_locked(cache_info);
- ++cache_info->revision_id;
+ } else {
+ if (cache_info->params.max_samples != old_max_samples) {
+ // If the maximum number of samples changes, the overhead of keeping the most recent
+ // samples around is not considered worth the effort, so they are cleared instead.
+ // All other parameters do not affect shared state: Changing these parameters does
+ // not invalidate the samples, as they only affect aggregation and the conditions
+ // under which servers are considered usable.
+ _res_cache_clear_stats_locked(cache_info);
+ ++cache_info->revision_id;
+ }
+ for (unsigned j = 0; j < numservers; j++) {
+ freeaddrinfo(nsaddrinfo[j]);
+ }
}
// Always update the search paths, since determining whether they actually changed is