From da4bbe74fb1b810e2219c0abe67a3cba3433c8da Mon Sep 17 00:00:00 2001 From: linxiaocong Date: Sun, 10 Sep 2017 14:56:25 +0800 Subject: [PATCH] fix segment fault when plugin and multi remote servers enabled --- src/local.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/local.c b/src/local.c index b3d4f671..538d9b70 100644 --- a/src/local.c +++ b/src/local.c @@ -1589,7 +1589,7 @@ main(int argc, char **argv) // Setup proxy context listen_ctx_t listen_ctx; - listen_ctx.remote_num = remote_num; + listen_ctx.remote_num = 0; listen_ctx.remote_addr = ss_malloc(sizeof(struct sockaddr *) * remote_num); memset(listen_ctx.remote_addr, 0, sizeof(struct sockaddr *) * remote_num); for (i = 0; i < remote_num; i++) { @@ -1606,6 +1606,7 @@ main(int argc, char **argv) FATAL("failed to resolve the provided hostname"); } listen_ctx.remote_addr[i] = (struct sockaddr *)storage; + ++listen_ctx.remote_num; if (plugin != NULL) break; } @@ -1699,7 +1700,7 @@ main(int argc, char **argv) ev_io_stop(loop, &listen_ctx.io); free_connections(loop); - for (i = 0; i < remote_num; i++) + for (i = 0; i < listen_ctx.remote_num; i++) ss_free(listen_ctx.remote_addr[i]); ss_free(listen_ctx.remote_addr); }