diff options
author | Nick Mathewson <nickm@torproject.org> | 2009-08-21 13:17:50 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2009-08-21 13:33:20 -0400 |
commit | d4a75a222f8da50caaafe42464809b0856f724eb (patch) | |
tree | 3f831df9896688556be6f109f517a51896976aa8 /src | |
parent | daa0326aaaa85a760be94ee2360cfa61a9fb5be2 (diff) | |
download | tor-d4a75a222f8da50caaafe42464809b0856f724eb.tar.gz tor-d4a75a222f8da50caaafe42464809b0856f724eb.zip |
Fix a memory leak in summarizing directory request timing.
Spotted by Coverity Scan.
Diffstat (limited to 'src')
-rw-r--r-- | src/or/geoip.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/or/geoip.c b/src/or/geoip.c index 5c13154205..ef0d29e09b 100644 --- a/src/or/geoip.c +++ b/src/or/geoip.c @@ -743,7 +743,8 @@ geoip_get_dirreq_history(geoip_client_action_t action, &ent->completion_time); if (time_diff == 0) time_diff = 1; /* Avoid DIV/0; "instant" answers are impossible - * anyway by law of nature or something.. */ + * by law of nature or something, but a milisecond + * is a bit greater than "instantly" */ *bytes_per_second = 1000 * ent->response_size / time_diff; smartlist_add(dirreq_times, bytes_per_second); complete++; @@ -767,8 +768,11 @@ geoip_get_dirreq_history(geoip_client_action_t action, result = tor_malloc_zero(bufsize); written = tor_snprintf(result, bufsize, "complete=%u,timeout=%u," "running=%u", complete, timeouts, running); - if (written < 0) + if (written < 0) { + SMARTLIST_FOREACH(dirreq_times, uint32_t *, dlt, tor_free(dlt)); + smartlist_free(dirreq_times); return NULL; + } #define MIN_DIR_REQ_RESPONSES 16 if (complete >= MIN_DIR_REQ_RESPONSES) { uint32_t *dltimes = tor_malloc(sizeof(uint32_t) * complete); @@ -794,9 +798,11 @@ geoip_get_dirreq_history(geoip_client_action_t action, dltimes[9*complete/10-1], dltimes[complete-1]); tor_free(dltimes); + } else { + SMARTLIST_FOREACH(dirreq_times, uint32_t *, dlt, tor_free(dlt)); } if (written < 0) - result = NULL; + tor_free(result); smartlist_free(dirreq_times); return result; } |