linux-erofs.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Gao Xiang <hsiangkao@redhat.com>
To: Hu Weiwen <sehuww@mail.scut.edu.cn>
Cc: linux-erofs@lists.ozlabs.org
Subject: Re: [PATCH 3/7] erofs-utils: tests: fix memory leakage in fssum
Date: Fri, 22 Jan 2021 07:45:13 +0800	[thread overview]
Message-ID: <20210121234513.GB2996701@xiangao.remote.csb> (raw)
In-Reply-To: <20210121163715.10660-4-sehuww@mail.scut.edu.cn>

Hi Weiwen,

On Fri, Jan 22, 2021 at 12:37:11AM +0800, Hu Weiwen wrote:
> Signed-off-by: Hu Weiwen <sehuww@mail.scut.edu.cn>

It just synced up with fstests, if you'd like to fix memory leakage of
this program. How about sending out it to fstests community directly?
fstests <fstests@vger.kernel.org>
and
https://lore.kernel.org/fstests/

So newer fssum here can be synced up again... (Also, kindly reminder,
before you submit it to fstests community, it'd be better leave some
commit message rather than leave it empty, since empty commit messge
(I mean only SOB) is somewhat uncommon for linux community...)

Thanks,
Gao Xiang

> ---
>  tests/src/fssum.c | 31 +++++++++++++++++--------------
>  1 file changed, 17 insertions(+), 14 deletions(-)
> 
> diff --git a/tests/src/fssum.c b/tests/src/fssum.c
> index 10d6275..0f40452 100644
> --- a/tests/src/fssum.c
> +++ b/tests/src/fssum.c
> @@ -31,6 +31,7 @@
>  #include <endian.h>
>  
>  #define CS_SIZE 16
> +#define CS_STR_SIZE (CS_SIZE * 2 + 1)
>  #define CHUNKS	128
>  
>  #ifdef __linux__
> @@ -209,16 +210,13 @@ sum_add_time(sum_t *dst, time_t t)
>  	sum_add_u64(dst, t);
>  }
>  
> -char *
> -sum_to_string(sum_t *dst)
> +void
> +sum_to_string(sum_t *dst, char *s)
>  {
>  	int i;
> -	char *s = alloc(CS_SIZE * 2 + 1);
>  
>  	for (i = 0; i < CS_SIZE; ++i)
>  		sprintf(s + i * 2, "%02x", dst->out[i]);
> -
> -	return s;
>  }
>  
>  int
> @@ -523,7 +521,7 @@ sum(int dirfd, int level, sum_t *dircs, char *path_prefix, char *path_in)
>  		exit(-1);
>  	}
>  
> -	d = fdopendir(dirfd);
> +	d = fdopendir(dup(dirfd));
>  	if (!d) {
>  		perror("opendir");
>  		exit(-1);
> @@ -547,6 +545,7 @@ sum(int dirfd, int level, sum_t *dircs, char *path_prefix, char *path_in)
>  		}
>  		++entries;
>  	}
> +	closedir(d);
>  	qsort(namelist, entries, sizeof(*namelist), namecmp);
>  	for (i = 0; i < entries; ++i) {
>  		struct stat64 st;
> @@ -674,21 +673,19 @@ sum(int dirfd, int level, sum_t *dircs, char *path_prefix, char *path_in)
>  		sum_fini(&meta);
>  		if (gen_manifest || in_manifest) {
>  			char *fn;
> -			char *m;
> -			char *c;
> +			char m[CS_STR_SIZE];
> +			char c[CS_STR_SIZE];
>  
>  			if (S_ISDIR(st.st_mode))
>  				strcat(path, "/");
>  			fn = escape(path);
> -			m = sum_to_string(&meta);
> -			c = sum_to_string(&cs);
> +			sum_to_string(&meta, m);
> +			sum_to_string(&cs, c);
>  
>  			if (gen_manifest)
>  				fprintf(out_fp, "%s %s %s\n", fn, m, c);
>  			if (in_manifest)
>  				check_manifest(fn, m, c, 0);
> -			free(c);
> -			free(m);
>  			free(fn);
>  		}
>  		sum_add_sum(dircs, &cs);
> @@ -696,6 +693,9 @@ sum(int dirfd, int level, sum_t *dircs, char *path_prefix, char *path_in)
>  next:
>  		free(path);
>  	}
> +	for (i = 0; i < entries; ++i)
> +		free(namelist[i]);
> +	free(namelist);
>  }
>  
>  int
> @@ -713,6 +713,7 @@ main(int argc, char *argv[])
>  	int elen;
>  	int n_flags = 0;
>  	const char *allopts = "heEfuUgGoOaAmMcCdDtTsSnNw:r:vx:";
> +	char sum_string[CS_STR_SIZE];
>  
>  	out_fp = stdout;
>  	while ((c = getopt(argc, argv, allopts)) != EOF) {
> @@ -871,9 +872,11 @@ main(int argc, char *argv[])
>  		if (!gen_manifest)
>  			fprintf(out_fp, "%s:", flagstring);
>  
> -		fprintf(out_fp, "%s\n", sum_to_string(&cs));
> +		sum_to_string(&cs, sum_string);
> +		fprintf(out_fp, "%s\n", sum_string);
>  	} else {
> -		if (strcmp(checksum, sum_to_string(&cs)) == 0) {
> +		sum_to_string(&cs, sum_string);
> +		if (strcmp(checksum, sum_string) == 0) {
>  			printf("OK\n");
>  			exit(0);
>  		} else {
> -- 
> 2.30.0
> 


  reply	other threads:[~2021-01-21 23:45 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-21 16:37 [PATCH 0/7] Setup tests Hu Weiwen
2021-01-21 16:37 ` [PATCH 1/7] erofs-utils: tests: fix when lz4 is not enabled Hu Weiwen
2021-01-22  0:21   ` Gao Xiang
2021-01-21 16:37 ` [PATCH 2/7] erofs-utils: tests: fix on out-of-tree build Hu Weiwen
2021-01-22  0:19   ` Gao Xiang
2021-01-21 16:37 ` [PATCH 3/7] erofs-utils: tests: fix memory leakage in fssum Hu Weiwen
2021-01-21 23:45   ` Gao Xiang [this message]
2021-01-21 16:37 ` [PATCH 4/7] erofs-utils: tests: fix distcheck Hu Weiwen
2021-01-22  0:16   ` Gao Xiang
2021-01-22  1:09     ` 胡玮文
2021-01-21 16:37 ` [PATCH 5/7] erofs-utils: tests: check battach on full buffer block Hu Weiwen
2021-01-21 16:41 ` [PATCH 6/7] erofs-utils: tests: fix fuse build order Hu Weiwen
2021-01-21 16:42 ` [PATCH 7/7] erofs-utils: tests: enable GitHub Actions Hu Weiwen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210121234513.GB2996701@xiangao.remote.csb \
    --to=hsiangkao@redhat.com \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=sehuww@mail.scut.edu.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).