From 761416a628f6468920db6ac52a36fdbd9eb83ab3 Mon Sep 17 00:00:00 2001 From: midipix Date: Thu, 13 May 2021 09:03:23 +0000 Subject: driver: stdin input: unlink temporary file upon freeing of driver context. --- src/driver/mdso_driver_ctx.c | 3 +++ src/driver/mdso_unit_ctx.c | 7 +++++-- src/internal/mdso_driver_impl.h | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/driver/mdso_driver_ctx.c b/src/driver/mdso_driver_ctx.c index e7e4a0f..46525f2 100644 --- a/src/driver/mdso_driver_ctx.c +++ b/src/driver/mdso_driver_ctx.c @@ -377,6 +377,9 @@ static void mdso_free_driver_ctx_impl(struct mdso_driver_ctx_alloc * ictx) if (ictx->ctx.fddst != AT_FDCWD) close(ictx->ctx.fddst); + if (ictx->ctx.fdtmpin >= 0) + unlink(ictx->ctx.tmpname); + if (ictx->ctx.fdtmpin >= 0) close(ictx->ctx.fdtmpin); diff --git a/src/driver/mdso_unit_ctx.c b/src/driver/mdso_unit_ctx.c index d14beed..1c6212c 100644 --- a/src/driver/mdso_unit_ctx.c +++ b/src/driver/mdso_unit_ctx.c @@ -42,7 +42,7 @@ static int mdso_stdin_to_tmp(const struct mdso_driver_ctx * dctx) ssize_t cnt; char * ch; char buf[4096]; - char template[] = "/tmp/mdso_stdin_to_tmp_XXXXXX"; + char tmpname[] = "/tmp/mdso_stdin_to_tmp_XXXXXX"; addr = (uintptr_t)dctx - offsetof(struct mdso_driver_ctx_impl,ctx); ictx = (struct mdso_driver_ctx_impl *)addr; @@ -50,14 +50,17 @@ static int mdso_stdin_to_tmp(const struct mdso_driver_ctx * dctx) if (ictx->fdtmpin >= 0) return dup(ictx->fdtmpin); - if ((fdtmp = mkstemp(template)) < 0) + if ((fdtmp = mkstemp(tmpname)) < 0) return -1; if ((ictx->fdtmpin = dup(fdtmp)) < 0) { close(fdtmp); + unlink(tmpname); return -1; } + strcpy(ictx->tmpname,tmpname); + for (;;) { ret = read(0,buf,sizeof(buf)-1); diff --git a/src/internal/mdso_driver_impl.h b/src/internal/mdso_driver_impl.h index dc37a66..02234f7 100644 --- a/src/internal/mdso_driver_impl.h +++ b/src/internal/mdso_driver_impl.h @@ -59,6 +59,7 @@ struct mdso_driver_ctx_impl { struct mdso_error_info** erricap; struct mdso_error_info * erriptr[64]; struct mdso_error_info erribuf[64]; + char tmpname[32]; }; struct mdso_unit_ctx_impl { -- cgit v1.2.3