From 496eda7eb23702e0559b6a2f92f2a9b731f463f8 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sat, 24 Jan 2026 15:43:38 +0100 Subject: [PATCH] statd: remove double-close of file descriptor after fclose When fdopen() succeeds, the FILE stream takes ownership of the file descriptor. Calling fclose() automatically closes the underlying fd, so the subsequent close(fd) calls were double-close bugs that could cause undefined behavior. Signed-off-by: Joachim Wiberg --- src/statd/statd.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/statd/statd.c b/src/statd/statd.c index da02b730..b07ce04c 100644 --- a/src/statd/statd.c +++ b/src/statd/statd.c @@ -96,7 +96,6 @@ static int ly_add_yanger_data(const struct ly_ctx *ctx, struct lyd_node **parent if (err) { ERROR("Error, running yanger"); fclose(stream); - close(fd); return SR_ERR_SYS; } @@ -105,7 +104,6 @@ static int ly_add_yanger_data(const struct ly_ctx *ctx, struct lyd_node **parent if (lseek(fd, 0, SEEK_SET) == (off_t)-1) { ERROR("Error, unable reset stream (seek)"); fclose(stream); - close(fd); return SR_ERR_SYS; } @@ -114,7 +112,7 @@ static int ly_add_yanger_data(const struct ly_ctx *ctx, struct lyd_node **parent ERROR("Error, parsing yanger data (%d)", err); fclose(stream); - close(fd); + /* Note: fclose() already closes the underlying fd from fdopen() */ return err; }