Skip to content

Commit

Permalink
just use malloc
Browse files Browse the repository at this point in the history
  • Loading branch information
mcspr committed Sep 15, 2019
1 parent 846af75 commit e3dfd52
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions code/espurna/libs/Http.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,15 @@ class AsyncHttp {
+ http->host.length()
+ http->path.length()
+ 32;
std::unique_ptr<char[]> headers(new (std::nothrow) char[headers_len + 1]);
char* headers = (char *) malloc(headers_len + 1);

if (!headers) {
ASYNC_HTTP_DEBUG("err | alloc %u fail\n", headers_len + 1);
client->close(true);
return;
}

int res = snprintf_P(headers.get(), headers_len + 1,
int res = snprintf_P(headers, headers_len + 1,
HTTP_REQUEST_TEMPLATE,
http->method.c_str(),
http->path.c_str(),
Expand All @@ -251,11 +251,14 @@ class AsyncHttp {
);
if (res >= (headers_len + 1)) {
ASYNC_HTTP_DEBUG("err | res>=len :: %u>=%u\n", res, headers_len + 1);
free(headers);
client->close(true);
return;
}

client->write(headers.get());
client->write(headers);
// TODO: streaming data source instead of using a simple String
// TODO: move to onPoll, ->add(data) and ->send() until it can't (returns 0), then repeat
client->write(http->data.c_str());

}
Expand Down

0 comments on commit e3dfd52

Please sign in to comment.