From 63fe12a789136d69261375a84b5f9e2091e3768c Mon Sep 17 00:00:00 2001 From: Alexander Scheel Date: Sep 14 2017 19:24:04 +0000 Subject: Fix error handling in gpm_send_buffer/gpm_recv_buffer. Signed-off-by: Alexander Scheel --- diff --git a/proxy/src/client/gpm_common.c b/proxy/src/client/gpm_common.c index 6d93a55..ee6306a 100644 --- a/proxy/src/client/gpm_common.c +++ b/proxy/src/client/gpm_common.c @@ -419,10 +419,7 @@ static int gpm_send_buffer(struct gpm_ctx *gpmctx, ret = 0; done: - if (ret) { - /* on errors we can only close the fd and return */ - gpm_close_socket(gpmctx); - } + /* we only need to return as gpm_retry_socket closes the socket */ return ret; } @@ -492,9 +489,10 @@ static int gpm_recv_buffer(struct gpm_ctx *gpmctx, done: if (ret) { - /* on errors we can only close the fd and return */ - gpm_close_socket(gpmctx); - gpm_epoll_close(gpmctx); + /* on errors, free the buffer to prevent calling + * xdr_destroy(&xdr_reply_ctx); */ + free(*buffer); + *buffer = NULL; } return ret; } @@ -569,10 +567,6 @@ static int gpm_send_recv_loop(struct gpm_ctx *gpmctx, char *send_buffer, /* Close and reopen socket before trying again */ ret = gpm_retry_socket(gpmctx); - /* Free buffer and set it to NULL to prevent free(xdr_reply_ctx) */ - free(*recv_buffer); - *recv_buffer = NULL; - if (ret != 0) return ret; ret = ETIMEDOUT;