Skip to content

Commit

Permalink
Only free the context after request and response were free'd
Browse files Browse the repository at this point in the history
  • Loading branch information
twose committed Nov 29, 2019
1 parent 151cdad commit f4cdff1
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 20 deletions.
7 changes: 3 additions & 4 deletions swoole_http2_server.cc
Expand Up @@ -41,10 +41,9 @@ http2_stream::http2_stream(int _fd, uint32_t _id)

http2_stream::~http2_stream()
{
if (ctx)
{
swoole_http_context_free(ctx);
}
ctx->stream = nullptr;
/* it will be free'd when request/response are free'd */
// swoole_http_context_free(ctx);
}

void http2_stream::reset(uint32_t error_code)
Expand Down
2 changes: 2 additions & 0 deletions swoole_http_request.cc
Expand Up @@ -263,7 +263,9 @@ static void php_swoole_http_request_free_object(zend_object *object)
if (ctx)
{
ctx->request.zobject = NULL;
swoole_http_context_free(ctx);
}

zend_object_std_dtor(&request->std);
}

Expand Down
10 changes: 2 additions & 8 deletions swoole_http_response.cc
Expand Up @@ -156,8 +156,10 @@ static void php_swoole_http_response_free_object(zend_object *object)
}
}
}
ctx->response.zobject = NULL;
swoole_http_context_free(ctx);
}

zend_object_std_dtor(&response->std);
}

Expand Down Expand Up @@ -696,10 +698,6 @@ static PHP_METHOD(swoole_http_response, end)
#endif
{
swoole_http_response_end(ctx, zdata, return_value);
if (!ctx->upgrade)
{
swoole_http_context_free(ctx);
}
}
}

Expand Down Expand Up @@ -1399,10 +1397,6 @@ static PHP_METHOD(swoole_http_response, redirect)
return;
}
swoole_http_response_end(ctx, nullptr, return_value);
if (!ctx->end)
{
swoole_http_context_free(ctx);
}
}

static PHP_METHOD(swoole_http_response, __destruct) { }
6 changes: 3 additions & 3 deletions swoole_http_server.cc
Expand Up @@ -247,11 +247,11 @@ void swoole_http_context_copy(http_context *src, http_context *dst)

void swoole_http_context_free(http_context *ctx)
{
if (ctx->request.zobject)
/* http context can only be free'd after request and response were free'd */
if (ctx->request.zobject || ctx->response.zobject)
{
php_swoole_http_request_set_context(ctx->request.zobject, NULL);
return;
}
php_swoole_http_response_set_context(ctx->response.zobject, NULL);
#ifdef SW_USE_HTTP2
if (ctx->stream)
{
Expand Down
5 changes: 0 additions & 5 deletions swoole_websocket_server.cc
Expand Up @@ -327,7 +327,6 @@ void swoole_websocket_onRequest(http_context *ctx)
ctx->send(ctx, (char *) bad_request, strlen(bad_request));
ctx->end = 1;
ctx->close(ctx);
swoole_http_context_free(ctx);
}

void swoole_sha1(const char *str, int _len, unsigned char *digest)
Expand Down Expand Up @@ -665,10 +664,6 @@ int swoole_websocket_onHandshake(swServer *serv, swListenPort *port, http_contex
{
serv->close(serv, fd, 1);
}
if (!ctx->end)
{
swoole_http_context_free(ctx);
}
return SW_OK;
}

Expand Down

0 comments on commit f4cdff1

Please sign in to comment.