fix memory leak bug

worker_generates_requests_to_global_queue
Xiaosu Lyu 3 years ago
parent 5ac779f5c4
commit 6e3d6ef311

@ -51,7 +51,7 @@ sandbox_set_as_returned(struct sandbox *sandbox, sandbox_state_t last_state)
sandbox_state_totals_increment(SANDBOX_RETURNED);
sandbox_state_totals_decrement(last_state);
http_session_set_response_header(sandbox->http, 200);
//http_session_set_response_header(sandbox->http, 200);
sandbox->http->state = HTTP_SESSION_EXECUTION_COMPLETE;
//http_session_send_response(sandbox->http, (void_star_cb)listener_thread_register_http_session);
sandbox->http = NULL;

@ -46,6 +46,8 @@ struct sandbox {
/* HTTP State */
struct http_session *http;
struct auto_buf response_body;
struct auto_buf response_header;
/* WebAssembly Module State */
struct module *module; /* the module this is an instance of */

@ -796,7 +796,8 @@ wasi_snapshot_preview1_backing_fd_write(wasi_context_t *context, __wasi_fd_t fd,
debuglog("STDERR from Sandbox: %.*s", iovs[i].buf_len, iovs[i].buf);
}
#endif
rc = fwrite(iovs[i].buf, 1, iovs[i].buf_len, s->http->response_body.handle);
//rc = fwrite(iovs[i].buf, 1, iovs[i].buf_len, s->http->response_body.handle);
rc = fwrite(iovs[i].buf, 1, iovs[i].buf_len, s->response_body.handle);
if (rc != iovs[i].buf_len) return __WASI_ERRNO_FBIG;
nwritten += rc;

@ -12,7 +12,6 @@
#include "sandbox_functions.h"
#include "runtime.h"
extern thread_local int thread_id;
uint64_t total_held[1024] = {0};
uint64_t longest_held[1024] = {0};
thread_local static struct priority_queue *local_runqueue_minheap;

@ -25,6 +25,20 @@ sandbox_log_allocation(struct sandbox *sandbox)
#endif
}
int
init_response_body(struct sandbox *sandbox)
{
if (sandbox->response_body.data == NULL) {
int rc = auto_buf_init(&sandbox->response_body);
if (rc < 0) {
printf("failed to init http body autobuf, exit\n");
exit(-1);
}
}
return 0;
}
/**
* Allocates a WebAssembly linear memory for a sandbox based on the starting_pages and max_pages globals present in
* the associated *.so module
@ -94,7 +108,8 @@ sandbox_prepare_execution_environment(struct sandbox *sandbox)
int rc;
rc = http_session_init_response_body(sandbox->http);
//rc = http_session_init_response_body(sandbox->http);
rc = init_response_body(sandbox);
if (rc < 0) {
error_message = "failed to allocate response body";
goto err_globals_allocation_failed;
@ -135,6 +150,14 @@ err_http_allocation_failed:
goto done;
}
void
deinit_response_body(struct sandbox *sandbox)
{
auto_buf_deinit(&sandbox->response_body);
}
void
sandbox_init(struct sandbox *sandbox, struct module *module, struct http_session *session, struct route *route,
struct tenant *tenant, uint64_t admissions_estimate)
@ -211,6 +234,8 @@ sandbox_deinit(struct sandbox *sandbox)
/* Linear Memory and Guard Page should already have been munmaped and set to NULL */
assert(sandbox->memory == NULL);
deinit_response_body(sandbox);
if (likely(sandbox->stack != NULL)) sandbox_free_stack(sandbox);
if (likely(sandbox->globals.buffer != NULL)) sandbox_free_globals(sandbox);
if (likely(sandbox->wasi_context != NULL)) wasi_context_destroy(sandbox->wasi_context);

Loading…
Cancel
Save