Skip to contentSkip to conversation

fsstress: fix memory leaks

PATCH In review Andrew Vagin 2 participants 7 messages Sep 26, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 fsstress: fix memory leaks

==11424== 156 bytes in 1 blocks are definitely lost in loss record 2 of 2

==11424==    at 0x4A0763E: malloc (vg_replace_malloc.c:207)
==11424==    by 0x402E4C: make_freq_table (fsstress.c:986)
==11424==    by 0x401C26: main (fsstress.c:410)

make_freq_table is executed on each iterations, but freq_table is not changed during test, so this patch moves it from the loop

---
 testcases/kernel/fs/fsstress/fsstress.c |   30 ++++++++++++++++--------------
 1 files changed, 16 insertions(+), 14 deletions(-)
testcases/kernel/fs/fsstress/fsstress.c +16 -14
index 1f11f6e..3df0ce5 100644
@@ -375,21 +375,24 @@ int main(int argc, char **argv)
 			break;
 		}
 	}
-        while ( (loopcntr <= loops) || (loops == 0) )
-        {
-		if (no_xfs && errtag) {
-			fprintf(stderr, "error injection only works on XFS\n");
-			exit(1);
-		}
 
-		if (no_xfs) {
-			int i;
-			for (i = 0; ops+i < ops_end; ++i) {
-				if (ops[i].isxfs)
-					ops[i].freq = 0;
-			}
+	if (no_xfs && errtag) {
+		fprintf(stderr, "error injection only works on XFS\n");
+		exit(1);
+	}
+
+	if (no_xfs) {
+		int i;
+		for (i = 0; ops+i < ops_end; ++i) {
+			if (ops[i].isxfs)
+				ops[i].freq = 0;
 		}
-       
+	}
+
+	make_freq_table();
+
+        while ( (loopcntr <= loops) || (loops == 0) )
+        {
        	 	if (!dirname) {
        	     	/* no directory specified */
     	        	if (!nousage) usage();
@@ -407,7 +410,6 @@ int main(int argc, char **argv)
 			maxfsize = (off64_t)MAXFSIZE32;
 		else
 			maxfsize = (off64_t)MAXFSIZE;
-		make_freq_table();
 		dcache_init();
 		setlinebuf(stdout);
 		if (!seed) {
Signature · 13 lines
1.6.2.5


------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#1 lore raw

PATCH 2/3 fsstress: fix memory leak in fread_d

1. check result from operation open before set flags
2. close descriptor and free path if set flags failed

valgrind --leak-check=full --show-reachable=yes ./fsstress -d /home/shpagin/git-archive/ltp/testcases/kernel/fs/fsstress/tmp -l 10 -n 100

==23212== 1,134 bytes in 108 blocks are definitely lost in loss record 4 of 5

==23212==    at 0x4A0776F: realloc (vg_replace_malloc.c:429)
==23212==    by 0x401E6A: append_pathname (fsstress.c:528)
==23212==    by 0x4024E3: fent_to_name (fsstress.c:760)
==23212==    by 0x40284F: get_fname (fsstress.c:846)
==23212==    by 0x4041E0: dread_f (fsstress.c:1757)
==23212==    by 0x402368: doproc (fsstress.c:728)
==23212==    by 0x401CC1: main (fsstress.c:463)
---
 testcases/kernel/fs/fsstress/fsstress.c |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)
testcases/kernel/fs/fsstress/fsstress.c +11 -5
index 3df0ce5..db6b358 100644
@@ -1764,10 +1764,6 @@ dread_f(int opno, long r)
 	}
 	fd = open_path(&f, O_RDONLY);
 
-	if (!setdirect(fd)) {
-		return;
-	}
-
 	e = fd < 0 ? errno : 0;
 	check_cwd();
 	if (fd < 0) {
@@ -1777,6 +1773,13 @@ dread_f(int opno, long r)
 		free_pathname(&f);
 		return;
 	}
+
+	if (!setdirect(fd)) {
+		close(fd);
+		free_pathname(&f);
+		return;
+	}
+
 	if (fstat64(fd, &stb) < 0) {
 		if (v)
 			printf("%d/%d: dread - fstat64 %s failed %d\n",
@@ -1864,8 +1867,11 @@ dwrite_f(int opno, long r)
 		return;
 	}
 
-	if (!setdirect(fd))
+	if (!setdirect(fd)) {
+		free_pathname(&f);
+		close(fd);
 		return;
+	}
 	if (fstat64(fd, &stb) < 0) {
 		if (v)
 			printf("%d/%d: dwrite - fstat64 %s failed %d\n",
Signature · 13 lines
1.6.2.5


------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#2 lore raw

PATCH 3/3 fsstress: renew flist if clean up test directory

flist contain all files created by fsstress. If test clean up direcory on each interations that it should reinitilize flist.

---
 testcases/kernel/fs/fsstress/fsstress.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
testcases/kernel/fs/fsstress/fsstress.c +7 -0
index db6b358..bf5df7c 100644
@@ -491,6 +491,13 @@ int main(int argc, char **argv)
 	{
 	  sprintf(cmd,"rm -rf %s/*",dirname);
 	  system(cmd);
+	  for (i = 0; i < FT_nft; i++) {
+	  	flist[i].nslots = 0;
+	  	flist[i].nfiles = 0;
+	  	free(flist[i].fents);
+	  	flist[i].fents = NULL;
+	  }
+
 	}
         loopcntr++;
 	}
Signature · 13 lines
1.6.2.5


------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#3 lore raw

Re: [LTP] [PATCH 3/3] fsstress: renew flist if clean up test directory

Quoted 15 lines · Andrew Vagin

flist contain all files created by fsstress. If test clean up direcory on each interations that it should reinitilize flist.

---
 testcases/kernel/fs/fsstress/fsstress.c |    7 +++++++

 1 files changed, 7 insertions(+), 0 deletions(-)
testcases/kernel/fs/fsstress/fsstress.c +0 -0
index db6b358..bf5df7c 100644
@@ -491,6 +491,13 @@ int main(int argc, char **argv)
        {
          sprintf(cmd,"rm -rf %s/*",dirname);
          system(cmd);

testcases/kernel/fs/fsstress/fsstress.c int main(int argc, char **argv) · line 503

Quoted 10 lines
testcases/kernel/fs/fsstress/fsstress.c +7 -0
+         for (i = 0; i < FT_nft; i++) {
+               flist[i].nslots = 0;
+               flist[i].nfiles = 0;
+               free(flist[i].fents);
+               flist[i].fents = NULL;
+         }
+
        }
         loopcntr++;
        }

Looks good :).
Thanks!
-Garrett

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#4 lore raw

Re: [LTP] [PATCH 2/3] fsstress: fix memory leak in fread_d

In reply to Andrew Vagin
Quoted 51 lines · Andrew Vagin

1. check result from operation open before set flags
2. close descriptor and free path if set flags failed

valgrind --leak-check=full --show-reachable=yes ./fsstress -d /home/shpagin/git-archive/ltp/testcases/kernel/fs/fsstress/tmp -l 10 -n 100

==23212== 1,134 bytes in 108 blocks are definitely lost in loss record 4 of 5 ==23212==    at 0x4A0776F: realloc (vg_replace_malloc.c:429) ==23212==    by 0x401E6A: append_pathname (fsstress.c:528) ==23212==    by 0x4024E3: fent_to_name (fsstress.c:760)
==23212==    by 0x40284F: get_fname (fsstress.c:846)
==23212==    by 0x4041E0: dread_f (fsstress.c:1757)
==23212==    by 0x402368: doproc (fsstress.c:728)
==23212==    by 0x401CC1: main (fsstress.c:463)

---
 testcases/kernel/fs/fsstress/fsstress.c |   16 +++++++++++-----

 1 files changed, 11 insertions(+), 5 deletions(-)
testcases/kernel/fs/fsstress/fsstress.c +7 -4
index 3df0ce5..db6b358 100644
@@ -1764,10 +1764,6 @@ dread_f(int opno, long r)
        }
        fd = open_path(&f, O_RDONLY);
 
-       if (!setdirect(fd)) {
-               return;
-       }
-
        e = fd < 0 ? errno : 0;
        check_cwd();
        if (fd < 0) {
@@ -1777,6 +1773,13 @@ dread_f(int opno, long r)
                free_pathname(&f);
                return;
        }
+
+       if (!setdirect(fd)) {
+               close(fd);
+               free_pathname(&f);
+               return;
+       }
+
        if (fstat64(fd, &stb) < 0) {
                if (v)
                        printf("%d/%d: dread - fstat64 %s failed %d\n",
@@ -1864,8 +1867,11 @@ dwrite_f(int opno, long r)
                return;
        }

testcases/kernel/fs/fsstress/fsstress.c dwrite_f(int opno, long r) · line 1877

Quoted 10 lines
testcases/kernel/fs/fsstress/fsstress.c +4 -1
 
-       if (!setdirect(fd))
+       if (!setdirect(fd)) {
+               free_pathname(&f);
+               close(fd);
                return;
+       }
        if (fstat64(fd, &stb) < 0) {
                if (v)
                        printf("%d/%d: dwrite - fstat64 %s failed %d\n",

Andrew,
This change looks good, but the indentation is a bit catywampus.
Please fix and run with checkpatch.pl.
Thanks!
-Garrett

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#5 lore raw
In reply to Andrew Vagin
Quoted 55 lines · Andrew Vagin

==11424== 156 bytes in 1 blocks are definitely lost in loss record 2 of 2 ==11424==    at 0x4A0763E: malloc (vg_replace_malloc.c:207) ==11424==    by 0x402E4C: make_freq_table (fsstress.c:986) ==11424==    by 0x401C26: main (fsstress.c:410)

make_freq_table is executed on each iterations, but freq_table is not changed during test, so this patch moves it from the loop
---
 testcases/kernel/fs/fsstress/fsstress.c |   30 ++++++++++++++++--------------

 1 files changed, 16 insertions(+), 14 deletions(-)
testcases/kernel/fs/fsstress/fsstress.c +16 -13
index 1f11f6e..3df0ce5 100644
@@ -375,21 +375,24 @@ int main(int argc, char **argv)
                        break;
                }
        }
-        while ( (loopcntr <= loops) || (loops == 0) )
-        {
-               if (no_xfs && errtag) {
-                       fprintf(stderr, "error injection only works on XFS\n");
-                       exit(1);
-               }
 
-               if (no_xfs) {
-                       int i;
-                       for (i = 0; ops+i < ops_end; ++i) {
-                               if (ops[i].isxfs)
-                                       ops[i].freq = 0;
-                       }
+       if (no_xfs && errtag) {
+               fprintf(stderr, "error injection only works on XFS\n");
+               exit(1);
+       }
+
+       if (no_xfs) {
+               int i;
+               for (i = 0; ops+i < ops_end; ++i) {
+                       if (ops[i].isxfs)
+                               ops[i].freq = 0;
                }
-
+       }
+
+       make_freq_table();
+
+        while ( (loopcntr <= loops) || (loops == 0) )
+        {
                        if (!dirname) {
                        /* no directory specified */
                        if (!nousage) usage();
@@ -407,7 +410,6 @@ int main(int argc, char **argv)
                        maxfsize = (off64_t)MAXFSIZE32;
Quoted 8 lines

               else
                       maxfsize = (off64_t)MAXFSIZE;
-               make_freq_table(); dcache_init(); setlinebuf(stdout);
               if (!seed) {
--
1.6.2.5

Andrew,
Please use tabs instead of spaces for indentation. Run
checkpatch.pl after everything's said and done to validate style. Thanks,
-Garrett

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#6 lore raw

On 09/27/2009 01:29 AM, Garrett Cooper wrote:

Thanks for your comments, I resent all patches.

Quoted 72 lines · Andrew Vagin
Quoted 63 lines

==11424== 156 bytes in 1 blocks are definitely lost in loss record 2 of 2

==11424==    at 0x4A0763E: malloc (vg_replace_malloc.c:207)
==11424==    by 0x402E4C: make_freq_table (fsstress.c:986)
==11424==    by 0x401C26: main (fsstress.c:410)

make_freq_table is executed on each iterations, but freq_table is not changed during test, so this patch moves it from the loop

---
  testcases/kernel/fs/fsstress/fsstress.c |   30 ++++++++++++++++--------------
  1 files changed, 16 insertions(+), 14 deletions(-)
testcases/kernel/fs/fsstress/fsstress.c +16 -15
index 1f11f6e..3df0ce5 100644
@@ -375,21 +375,24 @@ int main(int argc, char **argv)
                        break;
                }
        }
-        while ( (loopcntr<= loops) || (loops == 0) )
-        {
-               if (no_xfs&&  errtag) {
-                       fprintf(stderr, "error injection only works on XFS\n");
-                       exit(1);
-               }
 
-               if (no_xfs) {
-                       int i;
-                       for (i = 0; ops+i<  ops_end; ++i) {
-                               if (ops[i].isxfs)
-                                       ops[i].freq = 0;
-                       }
+       if (no_xfs&&  errtag) {
+               fprintf(stderr, "error injection only works on XFS\n");
+               exit(1);
+       }
+
+       if (no_xfs) {
+               int i;
+               for (i = 0; ops+i<  ops_end; ++i) {
+                       if (ops[i].isxfs)
+                               ops[i].freq = 0;
                }
-
+       }
+
+       make_freq_table();
+
+        while ( (loopcntr<= loops) || (loops == 0) )
+        {
                        if (!dirname) {
                        /* no directory specified */
                        if (!nousage) usage();
@@ -407,7 +410,6 @@ int main(int argc, char **argv)
                        maxfsize = (off64_t)MAXFSIZE32;
                else
                        maxfsize = (off64_t)MAXFSIZE;
-               make_freq_table();
                dcache_init();
                setlinebuf(stdout);
                if (!seed) {
--
Quoted 2 lines

1.6.2.5

Andrew,
Please use tabs instead of spaces for indentation. Run
checkpatch.pl after everything's said and done to validate style. Thanks,
-Garrett

Quoted 13 lines

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list