Fix filedescriptor/socket leaking

personal/stbuehler/wip
Stefan Bühler 9 years ago
parent f42ebc05f4
commit 4706cc5f60
  1. 8
      src/main/stream.c
  2. 3
      src/main/stream_simple_socket.c
  3. 8
      src/modules/fastcgi_stream.c
  4. 3
      src/modules/mod_openssl.c

@ -297,6 +297,8 @@ liStream* li_stream_null_new(liEventLoop *loop) {
static void iostream_destroy(liIOStream *iostream) {
int fd;
if (0 < iostream->stream_out.refcount || 0 < iostream->stream_in.refcount) return;
iostream->stream_out.refcount = iostream->stream_in.refcount = 1;
@ -313,12 +315,14 @@ static void iostream_destroy(liIOStream *iostream) {
iostream->write_timeout_queue = NULL;
}
iostream->cb(iostream, LI_IOSTREAM_DESTROY);
fd = li_event_io_fd(&iostream->io_watcher);
if (-1 != fd) close(fd); /* usually this should be shutdown+closed somewhere else */
li_event_clear(&iostream->io_watcher);
li_iostream_throttle_clear(iostream);
iostream->cb(iostream, LI_IOSTREAM_DESTROY);
assert(1 == iostream->stream_out.refcount);
assert(1 == iostream->stream_in.refcount);

@ -27,12 +27,13 @@ void li_stream_simple_socket_close(liIOStream *stream, gboolean aborted) {
}
} else {
liWorker *wrk = li_worker_from_iostream(stream);
li_event_clear(&stream->io_watcher);
li_event_clear(&stream->io_watcher); /* sets io_fd to -1 */
shutdown(fd, SHUT_WR);
li_stream_disconnect(&stream->stream_out);
li_worker_add_closing_socket(wrk, fd);
}
assert(-1 == li_event_io_fd(&stream->io_watcher));
}
static void stream_simple_socket_read_throttle_notify(liThrottleState *state, gpointer data) {

@ -196,8 +196,10 @@ static void backend_close(liBackendPool *bpool, liWorker *wrk, liBackendConnecti
fcgi_debug("%s\n", "backend_close");
if (NULL != ctx->iostream) {
int fd;
li_stream_simple_socket_close(ctx->iostream, FALSE);
li_iostream_reset(ctx->iostream);
fd = li_iostream_reset(ctx->iostream);
assert(-1 == fd);
ctx->iostream = NULL;
}
li_stream_reset(&ctx->fcgi_in);
@ -267,6 +269,7 @@ static void fastcgi_reset(liFastCGIBackendContext *ctx) {
if (!ctx->is_active) {
li_backend_connection_closed(ctx->pool->public.subpool, ctx->subcon);
} else {
int fd;
const liFastCGIBackendCallbacks *callbacks = ctx->pool->callbacks;
liFastCGIBackendConnection_p *currentcon = ctx->currentcon;
liIOStream *iostream = ctx->iostream;
@ -276,7 +279,8 @@ static void fastcgi_reset(liFastCGIBackendContext *ctx) {
ctx->request_done = TRUE;
ctx->iostream = NULL;
li_stream_simple_socket_close(iostream, TRUE);
li_iostream_reset(iostream);
fd = li_iostream_reset(iostream);
assert(-1 == fd);
li_stream_disconnect(&ctx->fcgi_out);
li_stream_disconnect_dest(&ctx->fcgi_in);

@ -203,7 +203,8 @@ static gboolean openssl_con_new(liConnection *con, int fd) {
if (NULL == conctx->ssl_filter) {
ERROR(srv, "SSL_new: %s", ERR_error_string(ERR_get_error(), NULL));
li_iostream_reset(conctx->sock_stream);
fd = li_iostream_reset(conctx->sock_stream);
close(fd);
g_slice_free(openssl_connection_ctx, conctx);
return FALSE;
}

Loading…
Cancel
Save