Skip to content

Commit

Permalink
api_client: fix lifespan management
Browse files Browse the repository at this point in the history
Signed-off-by: He Xian <[email protected]>
  • Loading branch information
hexian000 committed Nov 10, 2024
1 parent 624fac0 commit ede1a9c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/api_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ static void api_client_close(
CLOSE_FD(ctx->w_socket.fd);
}
ctx->parser.cbuf = VBUF_FREE(ctx->parser.cbuf);
session_del(&ctx->ss);
if (ctx->ss.close != NULL) {
/* managed by session */
session_del(&ctx->ss);
}
free(ctx);
}

Expand All @@ -73,10 +76,6 @@ api_ss_close(struct ev_loop *restrict loop, struct session *restrict ss)
{
struct api_client_ctx *restrict ctx =
DOWNCAST(struct session, struct api_client_ctx, ss, ss);
if (ctx->cb.func != NULL) {
/* managed by ruleset */
return;
}
api_client_close(loop, ctx);
}

Expand Down Expand Up @@ -319,8 +318,14 @@ static struct api_client_ctx *api_client_do(
.data = ctx,
};
dialer_init(&ctx->dialer, cb);
ctx->ss.close = api_ss_close;
session_add(&ctx->ss);
if (ctx->cb.func != NULL) {
/* managed by ruleset */
ctx->ss.close = NULL;
} else {
/* managed by session */
ctx->ss.close = api_ss_close;
session_add(&ctx->ss);
}

ev_timer_start(loop, &ctx->w_timeout);
dialer_start(&ctx->dialer, loop, req);
Expand Down
3 changes: 3 additions & 0 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ static void crash_handler(const int signo)
LOGE_F("sigaction: %s", strerror(errno));
_Exit(EXIT_FAILURE);
}
if (raise(signo)) {
_Exit(EXIT_FAILURE);
}
}

static void set_crash_handler(void)
Expand Down

0 comments on commit ede1a9c

Please sign in to comment.