@@ -2124,19 +2124,16 @@ static int
21242124handle_tmpcopyup (libcrun_container_t * container , const char * rootfs , const char * target ,
21252125 int copy_from_fd , libcrun_error_t * err )
21262126{
2127- int destfd , tmpfd , ret ;
2128-
2127+ int destfd , ret ;
2128+ cleanup_close int tmpfd = copy_from_fd ;
21292129 destfd = safe_openat (get_private_data (container )-> rootfsfd , rootfs , target ,
21302130 O_CLOEXEC | O_DIRECTORY , 0 , err );
21312131 if (UNLIKELY (destfd < 0 ))
21322132 return crun_error_wrap (err , "open `%s` to write for tmpcopyup" , target );
21332133
2134- /* take ownership for the fd. */
2135- tmpfd = get_and_reset (& copy_from_fd );
2136-
2134+ // copy_recursive_fd_to_fd closes tmpfd and destfd
21372135 ret = copy_recursive_fd_to_fd (tmpfd , destfd , target , target , err );
2138- close (destfd );
2139- close (tmpfd );
2136+ tmpfd = -1 ;
21402137
21412138 return ret ;
21422139}
@@ -2339,7 +2336,9 @@ process_single_mount (libcrun_container_t *container, const char *rootfs,
23392336
23402337 if (copy_from_fd >= 0 )
23412338 {
2339+ // handle_tmpcopyup closes copy_from_fd
23422340 ret = handle_tmpcopyup (container , rootfs , target , copy_from_fd , err );
2341+ copy_from_fd = -1 ;
23432342 if (UNLIKELY (ret < 0 ))
23442343 return ret ;
23452344 }
0 commit comments