Skip to content

Commit

Permalink
fix: do not free the method_str.ptr as we still require the memory
Browse files Browse the repository at this point in the history
fixes #352
  • Loading branch information
JakeChampion committed Dec 16, 2022
1 parent f026dcf commit 17c5049
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions c-dependencies/js-compute-runtime/js-compute-builtins.cpp
Expand Up @@ -3851,19 +3851,20 @@ static bool init_downstream_request(JSContext *cx, HandleObject request) {
bool is_get = strncmp(method_str.ptr, "GET", method_str.len) == 0;
if (!is_get) {
RootedString method(cx, JS_NewStringCopyN(cx, method_str.ptr, method_str.len));
JS_free(cx, method_str.ptr);
if (!method) {
return false;
}

JS::SetReservedSlot(request, Request::Slots::Method, JS::StringValue(method));
}

bool is_head = strncmp(method_str.ptr, "HEAD", method_str.len) == 0;

// Set whether we have a body depending on the method.
// TODO: verify if that's right. I.e. whether we should treat all requests
// that are not GET or HEAD as having a body, which might just be 0-length.
// It's not entirely clear what else we even could do here though.
if (!(is_get || strncmp(method_str.ptr, "HEAD", method_str.len) == 0)) {
if (!is_get && !is_head) {
JS::SetReservedSlot(request, Request::Slots::HasBody, JS::TrueValue());
}

Expand Down

0 comments on commit 17c5049

Please sign in to comment.