Skip to content

Commit

Permalink
fix HTTPClientResponse memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinNowak committed Apr 23, 2017
1 parent 177a00e commit 4d3030a
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/alertd.d
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,19 @@ class Graphite : DataSource
// add a 60s lag to avoid incorrect results for out-of-order collectd stats
auto url = url ~ "/render?from=-" ~ (ago + 1.minutes).total!"seconds".to!string ~ "s&until=-60s&"
~ "format=raw&target=" ~ encodeComponent(query);
auto response = requestHTTP(url);
auto content = response.bodyReader.readAllUTF8;
enforceHTTP(response.statusCode == 200, cast(HTTPStatus) response.statusCode,
content);
Serie[] series;
requestHTTP(url, (scope req) { }, (scope res) {
auto content = res.bodyReader.readAllUTF8;
enforceHTTP(res.statusCode == 200, cast(HTTPStatus) res.statusCode, content);
series = parseGraphite(content, maxDataPoints);
});
return series;
}

private:

Serie[] parseGraphite(string content, int maxDataPoints = -1)
{
Serie[] series;
foreach (line; content.lineSplitter)
{
Expand Down Expand Up @@ -317,7 +325,6 @@ class Graphite : DataSource
return series;
}

private:
string url;
}

Expand Down

0 comments on commit 4d3030a

Please sign in to comment.