mirror of
https://github.com/openappsec/attachment.git
synced 2025-11-17 01:41:54 +03:00
fix large file inspection and free memory
This commit is contained in:
@@ -98,6 +98,24 @@ static int lua_get_redirect_page(lua_State *L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Free HttpMetaData memory
|
||||
static int lua_free_http_metadata(lua_State *L) {
|
||||
HttpMetaData *metadata = (HttpMetaData *)lua_touserdata(L, 1);
|
||||
if (!metadata) return 0;
|
||||
|
||||
if (metadata->http_protocol.data) free(metadata->http_protocol.data);
|
||||
if (metadata->method_name.data) free(metadata->method_name.data);
|
||||
if (metadata->host.data) free(metadata->host.data);
|
||||
if (metadata->listening_ip.data) free(metadata->listening_ip.data);
|
||||
if (metadata->uri.data) free(metadata->uri.data);
|
||||
if (metadata->client_ip.data) free(metadata->client_ip.data);
|
||||
if (metadata->parsed_host.data) free(metadata->parsed_host.data);
|
||||
if (metadata->parsed_uri.data) free(metadata->parsed_uri.data);
|
||||
free(metadata);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Allocate memory for nano_str_t (long-lived, must be freed later)
|
||||
static int lua_createNanoStrAlloc(lua_State *L) {
|
||||
@@ -531,6 +549,17 @@ static int lua_send_response_headers(lua_State *L) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
// Free verdict response memory
|
||||
static int lua_free_verdict_response(lua_State *L) {
|
||||
AttachmentVerdictResponse *response = (AttachmentVerdictResponse *)lua_touserdata(L, 1);
|
||||
if (!response) return 0;
|
||||
|
||||
// Free the AttachmentVerdictResponse structure
|
||||
free(response);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Register functions in Lua
|
||||
static const struct luaL_Reg nano_attachment_lib[] = {
|
||||
{"init_nano_attachment", lua_init_nano_attachment},
|
||||
@@ -550,6 +579,8 @@ static const struct luaL_Reg nano_attachment_lib[] = {
|
||||
{"freeHttpHeaders", lua_freeHttpHeaders},
|
||||
{"setHeaderCount", lua_setHeaderCount},
|
||||
{"create_http_metadata", lua_create_http_metadata},
|
||||
{"free_http_metadata", lua_free_http_metadata},
|
||||
{"free_verdict_response", lua_free_verdict_response},
|
||||
{"send_body", lua_send_body},
|
||||
{"end_inspection", lua_end_inspection},
|
||||
{NULL, NULL}
|
||||
|
||||
Reference in New Issue
Block a user