diff mbox series

[1/3] stream_interface: Close the file descriptor on failure

Message ID 20210724150605.567038-1-festevam@gmail.com
State Accepted
Headers show
Series [1/3] stream_interface: Close the file descriptor on failure | expand

Commit Message

Fabio Estevam July 24, 2021, 3:06 p.m. UTC
When img_check_free_space() fails the previously acquired file
descriptor should be closed.

Signed-off-by: Fabio Estevam <festevam@gmail.com>
---
 core/stream_interface.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Fabio Estevam July 24, 2021, 3:18 p.m. UTC | #1
On Sat, Jul 24, 2021 at 12:06 PM Fabio Estevam <festevam@gmail.com> wrote:
>
> When img_check_free_space() fails the previously acquired file
> descriptor should be closed.
>
> Signed-off-by: Fabio Estevam <festevam@gmail.com>

Sorry for sending the series twice. The first one missed the third patch.

Thanks
Stefano Babic July 25, 2021, 10:33 a.m. UTC | #2
Hi Fabio,

On 24.07.21 17:06, Fabio Estevam wrote:
> When img_check_free_space() fails the previously acquired file
> descriptor should be closed.
> 
> Signed-off-by: Fabio Estevam <festevam@gmail.com>
> ---
>   core/stream_interface.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/core/stream_interface.c b/core/stream_interface.c
> index efa9cbd64edb..da0c73353e50 100644
> --- a/core/stream_interface.c
> +++ b/core/stream_interface.c
> @@ -222,8 +222,10 @@ static int extract_files(int fd, struct swupdate_cfg *software)
>   				fdout = openfileoutput(img->extract_file);
>   				if (fdout < 0)
>   					return -1;
> -				if (!img_check_free_space(img, fdout))
> +				if (!img_check_free_space(img, fdout)) {
> +					close(fdout);
>   					return -1;
> +				}
>   				if (copyfile(fd, &fdout, fdh.size, &offset, 0, 0, 0, &checksum, img->sha256, false, NULL, NULL) < 0) {
>   					close(fdout);
>   					return -1;
> 

Series applied to -master, thanks !

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/core/stream_interface.c b/core/stream_interface.c
index efa9cbd64edb..da0c73353e50 100644
--- a/core/stream_interface.c
+++ b/core/stream_interface.c
@@ -222,8 +222,10 @@  static int extract_files(int fd, struct swupdate_cfg *software)
 				fdout = openfileoutput(img->extract_file);
 				if (fdout < 0)
 					return -1;
-				if (!img_check_free_space(img, fdout))
+				if (!img_check_free_space(img, fdout)) {
+					close(fdout);
 					return -1;
+				}
 				if (copyfile(fd, &fdout, fdh.size, &offset, 0, 0, 0, &checksum, img->sha256, false, NULL, NULL) < 0) {
 					close(fdout);
 					return -1;