Skip to content

Commit

Permalink
pmproxy: fix memory leaks picked up by coverity scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
natoscott committed May 15, 2019
1 parent 0107493 commit fdb6b8a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/pmproxy/src/grafana.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ on_grafana_value(pmSID sid, pmSeriesValue *value, void *arg)
}
baton->values++;
result = sdscatfmt(result, "%s[%S,%s]", prefix, quoted, timestamp);
sdsfree(quoted);

http_set_buffer(client, result, HTTP_FLAG_JSON);
http_transfer(client);
Expand Down
15 changes: 8 additions & 7 deletions src/pmproxy/src/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,14 +546,14 @@ static int
on_header_field(http_parser *request, const char *offset, size_t length)
{
struct client *client = (struct client *)request->data;
sds field = sdsnewlen(offset, length);

if (pmDebugOptions.http)
fprintf(stderr, "Header field: %s (client=%p)\n", field, client);
sds field;

if (client->u.http.parser.status_code || !client->u.http.headers)
return 0; /* already in process of failing connection */

field = sdsnewlen(offset, length);
if (pmDebugOptions.http)
fprintf(stderr, "Header field: %s (client=%p)\n", field, client);
/*
* Insert this header into the dictionary (name only so far);
* track this header for associating the value to it (below).
Expand All @@ -566,13 +566,14 @@ static int
on_header_value(http_parser *request, const char *offset, size_t length)
{
struct client *client = (struct client *)request->data;
sds value = sdsnewlen(offset, length);
sds value;

if (pmDebugOptions.http)
fprintf(stderr, "Header value: %s (client=%p)\n", value, client);
if (client->u.http.parser.status_code || !client->u.http.headers)
return 0; /* already in process of failing connection */

value = sdsnewlen(offset, length);
if (pmDebugOptions.http)
fprintf(stderr, "Header value: %s (client=%p)\n", value, client);
dictSetVal(client->u.http.headers, (dictEntry *)client->u.http.privdata, value);
return 0;
}
Expand Down
10 changes: 7 additions & 3 deletions src/pmproxy/src/series.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ on_pmseries_match(pmSID sid, void *arg)
pmSeriesBaton *baton = (pmSeriesBaton *)arg;
struct client *client = baton->client;
const char *prefix;
sds result = http_get_buffer(baton->client);
sds result;

if (baton->sid == NULL || sdscmp(baton->sid, sid) != 0) {
result = http_get_buffer(baton->client);
if (baton->series++ == 0) {
baton->suffix = json_push_suffix(baton->suffix, JSON_FLAG_ARRAY);
prefix = "[";
Expand Down Expand Up @@ -277,11 +278,13 @@ on_pmseries_label(pmSID sid, sds label, void *arg)
pmSeriesBaton *baton = (pmSeriesBaton *)arg;
struct client *client = baton->client;
const char *prefix;
sds s, result = http_get_buffer(client);
sds s, result;

if (baton->nsids != 0)
return 0;

result = http_get_buffer(client);

if (sid == NULL) { /* all labels globally requested */
if (baton->values == 0) {
baton->suffix = json_push_suffix(baton->suffix, JSON_FLAG_ARRAY);
Expand Down Expand Up @@ -322,13 +325,14 @@ on_pmseries_labelmap(pmSID sid, pmSeriesLabel *label, void *arg)
pmSeriesBaton *baton = (pmSeriesBaton *)arg;
struct client *client = baton->client;
const char *prefix;
sds s, name, value, result = http_get_buffer(client);
sds s, name, value, result;

if (baton->nsids == 0)
return 0;

name = label->name;
value = label->value;
result = http_get_buffer(client);

if ((s = baton->sid) == NULL) {
baton->sid = sdsdup(sid);
Expand Down

0 comments on commit fdb6b8a

Please sign in to comment.