Skip to content

Commit e3dfd52

Browse files
committed
just use malloc
1 parent 846af75 commit e3dfd52

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

code/espurna/libs/Http.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,15 @@ class AsyncHttp {
234234
+ http->host.length()
235235
+ http->path.length()
236236
+ 32;
237-
std::unique_ptr<char[]> headers(new (std::nothrow) char[headers_len + 1]);
237+
char* headers = (char *) malloc(headers_len + 1);
238238

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

245-
int res = snprintf_P(headers.get(), headers_len + 1,
245+
int res = snprintf_P(headers, headers_len + 1,
246246
HTTP_REQUEST_TEMPLATE,
247247
http->method.c_str(),
248248
http->path.c_str(),
@@ -251,11 +251,14 @@ class AsyncHttp {
251251
);
252252
if (res >= (headers_len + 1)) {
253253
ASYNC_HTTP_DEBUG("err | res>=len :: %u>=%u\n", res, headers_len + 1);
254+
free(headers);
254255
client->close(true);
255256
return;
256257
}
257258

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

261264
}

0 commit comments

Comments
 (0)