Re: [hackers] [sbase] libutil/cp.c leaks

From: Silvan Jegen <s.jegen_AT_gmail.com>
Date: Sun, 7 May 2017 19:27:49 +0200

Heyho

On Sun, May 07, 2017 at 01:54:42PM +0200, Hiltjo Posthuma wrote:
> I think there are some cases where libutil/cp.c can leak file descriptors.
> It is a warning case, but the descriptors are not closed.
>
> I think only `mv` is affected.
>
> Patch below:
>
>
> From af392d1a764d7420c7b05bb9e13d7766a5979894 Mon Sep 17 00:00:00 2001
> From: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
> Date: Sun, 7 May 2017 13:50:26 +0200
> Subject: [PATCH] libutil: fix leaks
>
> ---
> libutil/cp.c | 4 ++++
> 1 file changed, 4 insertions(+)

Looks good to me!


Cheers,

Silvan
 

> diff --git a/libutil/cp.c b/libutil/cp.c
> index 9bb517a..a8db0a2 100644
> --- a/libutil/cp.c
> +++ b/libutil/cp.c
> _AT_@ -79,6 +79,7 @@ cp(const char *s1, const char *s2, int depth)
> if (mkdir(s2, st.st_mode) < 0 && errno != EEXIST) {
> weprintf("mkdir %s:", s2);
> cp_status = 1;
> + closedir(dp);
> return 0;
> }
>
> _AT_@ -122,15 +123,18 @@ cp(const char *s1, const char *s2, int depth)
> if (unlink(s2) < 0 && errno != ENOENT) {
> weprintf("unlink %s:", s2);
> cp_status = 1;
> + fclose(f1);
> return 0;
> } else if (!(f2 = fopen(s2, "w"))) {
> weprintf("fopen %s:", s2);
> cp_status = 1;
> + fclose(f1);
> return 0;
> }
> } else {
> weprintf("fopen %s:", s2);
> cp_status = 1;
> + fclose(f1);
> return 0;
> }
> }
> --
> 2.12.2
>
>
>
> --
> Kind regards,
> Hiltjo
>
Received on Sun May 07 2017 - 19:27:49 CEST

This archive was generated by hypermail 2.3.0 : Sun May 07 2017 - 19:36:17 CEST