All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/5] kernel/syscalls/mmap: remove unused cleanup()
@ 2015-05-06  7:26 Wei,Jiangang
  2015-05-06  7:26 ` [LTP] [PATCH 2/5] kernel/syscalls/ipc/lib: Don't allocate memory for getpwnam() Wei,Jiangang
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Wei,Jiangang @ 2015-05-06  7:26 UTC (permalink / raw)
  To: ltp-list

Signed-off-by: Wei,Jiangang <weijg.fnst@cn.fujitsu.com>
---
 testcases/kernel/syscalls/mmap/mmap02.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/testcases/kernel/syscalls/mmap/mmap02.c b/testcases/kernel/syscalls/mmap/mmap02.c
index b7972f1..829f333 100644
--- a/testcases/kernel/syscalls/mmap/mmap02.c
+++ b/testcases/kernel/syscalls/mmap/mmap02.c
@@ -148,7 +148,6 @@ static void setup(void)
 		free(tst_buff);
 		tst_brkm(TFAIL | TERRNO, cleanup,
 			 "writing to %s failed", TEMPFILE);
-		cleanup();
 	}
 
 	/* Free the memory allocated for test buffer */
-- 
1.9.3


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [LTP] [PATCH 2/5] kernel/syscalls/ipc/lib: Don't allocate memory for getpwnam()
  2015-05-06  7:26 [LTP] [PATCH 1/5] kernel/syscalls/mmap: remove unused cleanup() Wei,Jiangang
@ 2015-05-06  7:26 ` Wei,Jiangang
  2015-05-07 13:21   ` Cyril Hrubis
  2015-05-06  7:26 ` [LTP] [PATCH 3/5] kernel/mem/hugetlb/lib: " Wei,Jiangang
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 15+ messages in thread
From: Wei,Jiangang @ 2015-05-06  7:26 UTC (permalink / raw)
  To: ltp-list

The getpwnam() function returns a pointer to a passwd
structure.
so Just need to declare a pointer to this structure,
not to allocate memory for it.

Signed-off-by: Wei,Jiangang <weijg.fnst@cn.fujitsu.com>
---
 testcases/kernel/syscalls/ipc/lib/libipc.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/testcases/kernel/syscalls/ipc/lib/libipc.c b/testcases/kernel/syscalls/ipc/lib/libipc.c
index f10e257..93fe6ce 100644
--- a/testcases/kernel/syscalls/ipc/lib/libipc.c
+++ b/testcases/kernel/syscalls/ipc/lib/libipc.c
@@ -141,13 +141,7 @@ void rm_sema(int sem_id)
  */
 int getuserid(char *user)
 {
-	struct passwd *ent;
-
-	/* allocate some space for the passwd struct */
-	if ((ent = malloc(sizeof(struct passwd))) == NULL) {
-		tst_brkm(TBROK, cleanup, "couldn't allocate space for passwd"
-			 " structure");
-	}
+	struct passwd *ent = NULL;
 
 	/* get the uid value for the user */
 	if ((ent = getpwnam(user)) == NULL) {
-- 
1.9.3


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [LTP] [PATCH 3/5] kernel/mem/hugetlb/lib: Don't allocate memory for getpwnam()
  2015-05-06  7:26 [LTP] [PATCH 1/5] kernel/syscalls/mmap: remove unused cleanup() Wei,Jiangang
  2015-05-06  7:26 ` [LTP] [PATCH 2/5] kernel/syscalls/ipc/lib: Don't allocate memory for getpwnam() Wei,Jiangang
@ 2015-05-06  7:26 ` Wei,Jiangang
  2015-05-07 13:21   ` Cyril Hrubis
  2015-05-06  7:26 ` [LTP] [PATCH 4/5] kernel/syscalls/dup2: free fildes to avoid memory leak Wei,Jiangang
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 15+ messages in thread
From: Wei,Jiangang @ 2015-05-06  7:26 UTC (permalink / raw)
  To: ltp-list

It requests to declare a pointer to for getpwnam() returns,
not to allocate memory for it.
This patch does the same as 2c0c4b3.

Signed-off-by: Wei,Jiangang <weijg.fnst@cn.fujitsu.com>
---
 testcases/kernel/mem/hugetlb/lib/libipc.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/testcases/kernel/mem/hugetlb/lib/libipc.c b/testcases/kernel/mem/hugetlb/lib/libipc.c
index 21fd8da..cfcde6b 100644
--- a/testcases/kernel/mem/hugetlb/lib/libipc.c
+++ b/testcases/kernel/mem/hugetlb/lib/libipc.c
@@ -83,11 +83,7 @@ int getipckey(void)
  */
 int getuserid(char *user)
 {
-	struct passwd *ent;
-
-	ent = malloc(sizeof(struct passwd));
-	if (ent == NULL)
-		tst_brkm(TBROK | TERRNO, cleanup, "malloc ent");
+	struct passwd *ent = NULL;
 
 	ent = getpwnam(user);
 	if (ent == NULL)
-- 
1.9.3


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [LTP] [PATCH 4/5] kernel/syscalls/dup2: free fildes to avoid memory leak
  2015-05-06  7:26 [LTP] [PATCH 1/5] kernel/syscalls/mmap: remove unused cleanup() Wei,Jiangang
  2015-05-06  7:26 ` [LTP] [PATCH 2/5] kernel/syscalls/ipc/lib: Don't allocate memory for getpwnam() Wei,Jiangang
  2015-05-06  7:26 ` [LTP] [PATCH 3/5] kernel/mem/hugetlb/lib: " Wei,Jiangang
@ 2015-05-06  7:26 ` Wei,Jiangang
  2015-05-07 13:26   ` Cyril Hrubis
  2015-05-06  7:26 ` [LTP] [PATCH 5/5] kernel/syscalls/fallocate: move fclose out of if-block Wei,Jiangang
  2015-05-07 13:22 ` [LTP] [PATCH 1/5] kernel/syscalls/mmap: remove unused cleanup() Cyril Hrubis
  4 siblings, 1 reply; 15+ messages in thread
From: Wei,Jiangang @ 2015-05-06  7:26 UTC (permalink / raw)
  To: ltp-list

Signed-off-by: Wei,Jiangang <weijg.fnst@cn.fujitsu.com>
---
 testcases/kernel/syscalls/dup2/dup205.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/testcases/kernel/syscalls/dup2/dup205.c b/testcases/kernel/syscalls/dup2/dup205.c
index 14218dd..a77ae0d 100644
--- a/testcases/kernel/syscalls/dup2/dup205.c
+++ b/testcases/kernel/syscalls/dup2/dup205.c
@@ -111,6 +111,7 @@ int main(int ac, char *av[])
 		unlink(pfilname);
 		for (ifile = fildes[0]; ifile < min + 10; ifile++)
 			close(fildes[ifile]);
+		free(fildes);
 		if (local_flag == PASSED) {
 			tst_resm(TPASS, "Test passed.");
 		} else {
-- 
1.9.3


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [LTP] [PATCH 5/5] kernel/syscalls/fallocate: move fclose out of if-block
  2015-05-06  7:26 [LTP] [PATCH 1/5] kernel/syscalls/mmap: remove unused cleanup() Wei,Jiangang
                   ` (2 preceding siblings ...)
  2015-05-06  7:26 ` [LTP] [PATCH 4/5] kernel/syscalls/dup2: free fildes to avoid memory leak Wei,Jiangang
@ 2015-05-06  7:26 ` Wei,Jiangang
  2015-05-07 13:32   ` Cyril Hrubis
  2015-05-07 13:22 ` [LTP] [PATCH 1/5] kernel/syscalls/mmap: remove unused cleanup() Cyril Hrubis
  4 siblings, 1 reply; 15+ messages in thread
From: Wei,Jiangang @ 2015-05-06  7:26 UTC (permalink / raw)
  To: ltp-list

It will encounter resource leak for fp as the old flow,
while fopen succeeds and the pointer para is NULL.
This patch aims to avoid this resource leak.

Signed-off-by: Wei,Jiangang <weijg.fnst@cn.fujitsu.com>
---
 testcases/kernel/sched/hyperthreading/ht_interrupt/ht_utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/testcases/kernel/sched/hyperthreading/ht_interrupt/ht_utils.c b/testcases/kernel/sched/hyperthreading/ht_interrupt/ht_utils.c
index 1c33d0c..c845cf8 100644
--- a/testcases/kernel/sched/hyperthreading/ht_interrupt/ht_utils.c
+++ b/testcases/kernel/sched/hyperthreading/ht_interrupt/ht_utils.c
@@ -30,8 +30,8 @@ int is_cmdline_para(const char *para)
 				return 1;
 			}
 		}
-		fclose(fp);
 	}
+	if (fp != NULL)	fclose(fp);
 
 	return 0;
 }
-- 
1.9.3


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [LTP] [PATCH 2/5] kernel/syscalls/ipc/lib: Don't allocate memory for getpwnam()
  2015-05-06  7:26 ` [LTP] [PATCH 2/5] kernel/syscalls/ipc/lib: Don't allocate memory for getpwnam() Wei,Jiangang
@ 2015-05-07 13:21   ` Cyril Hrubis
  2015-05-08  3:28     ` [LTP] [PATCH v2 " Wei,Jiangang
  0 siblings, 1 reply; 15+ messages in thread
From: Cyril Hrubis @ 2015-05-07 13:21 UTC (permalink / raw)
  To: Wei,Jiangang; +Cc: ltp-list

Hi!
>  int getuserid(char *user)
>  {
> -	struct passwd *ent;
> -
> -	/* allocate some space for the passwd struct */
> -	if ((ent = malloc(sizeof(struct passwd))) == NULL) {
> -		tst_brkm(TBROK, cleanup, "couldn't allocate space for passwd"
> -			 " structure");
> -	}
> +	struct passwd *ent = NULL;

Why do you initialize the pointer with NULL? If it's only used to store
the return from getpwnam()...

Otherwise, this is a good catch :)

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [LTP] [PATCH 3/5] kernel/mem/hugetlb/lib: Don't allocate memory for getpwnam()
  2015-05-06  7:26 ` [LTP] [PATCH 3/5] kernel/mem/hugetlb/lib: " Wei,Jiangang
@ 2015-05-07 13:21   ` Cyril Hrubis
  2015-05-08  3:31     ` [LTP] [PATCH v2 " Wei,Jiangang
  2015-05-08  8:33     ` [LTP] [PATCH v3 3/5] kernel/mem/hugetlb/lib: do refactor for getuserid Wei,Jiangang
  0 siblings, 2 replies; 15+ messages in thread
From: Cyril Hrubis @ 2015-05-07 13:21 UTC (permalink / raw)
  To: Wei,Jiangang; +Cc: ltp-list

Hi!
> +	struct passwd *ent = NULL;

Here as well.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [LTP] [PATCH 1/5] kernel/syscalls/mmap: remove unused cleanup()
  2015-05-06  7:26 [LTP] [PATCH 1/5] kernel/syscalls/mmap: remove unused cleanup() Wei,Jiangang
                   ` (3 preceding siblings ...)
  2015-05-06  7:26 ` [LTP] [PATCH 5/5] kernel/syscalls/fallocate: move fclose out of if-block Wei,Jiangang
@ 2015-05-07 13:22 ` Cyril Hrubis
  4 siblings, 0 replies; 15+ messages in thread
From: Cyril Hrubis @ 2015-05-07 13:22 UTC (permalink / raw)
  To: Wei,Jiangang; +Cc: ltp-list

Hi!
Pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [LTP] [PATCH 4/5] kernel/syscalls/dup2: free fildes to avoid memory leak
  2015-05-06  7:26 ` [LTP] [PATCH 4/5] kernel/syscalls/dup2: free fildes to avoid memory leak Wei,Jiangang
@ 2015-05-07 13:26   ` Cyril Hrubis
  2015-05-08  3:33     ` [LTP] [PATCH v2 4/5] kernel/syscalls/dup2: optimize allocation and free Wei,Jiangang
  0 siblings, 1 reply; 15+ messages in thread
From: Cyril Hrubis @ 2015-05-07 13:26 UTC (permalink / raw)
  To: Wei,Jiangang; +Cc: ltp-list

Hi!
> Signed-off-by: Wei,Jiangang <weijg.fnst@cn.fujitsu.com>
> ---
>  testcases/kernel/syscalls/dup2/dup205.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/testcases/kernel/syscalls/dup2/dup205.c b/testcases/kernel/syscalls/dup2/dup205.c
> index 14218dd..a77ae0d 100644
> --- a/testcases/kernel/syscalls/dup2/dup205.c
> +++ b/testcases/kernel/syscalls/dup2/dup205.c
> @@ -111,6 +111,7 @@ int main(int ac, char *av[])
>  		unlink(pfilname);
>  		for (ifile = fildes[0]; ifile < min + 10; ifile++)
>  			close(fildes[ifile]);
> +		free(fildes);
>  		if (local_flag == PASSED) {
>  			tst_resm(TPASS, "Test passed.");
>  		} else {

Can you also move the allocation and free outside the TEST_LOOPING loop?

Ideally to the cleanup and setup?

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [LTP] [PATCH 5/5] kernel/syscalls/fallocate: move fclose out of if-block
  2015-05-06  7:26 ` [LTP] [PATCH 5/5] kernel/syscalls/fallocate: move fclose out of if-block Wei,Jiangang
@ 2015-05-07 13:32   ` Cyril Hrubis
  2015-05-08  3:39     ` [LTP] [PATCH v2 5/5] kernel/syscalls/fallocate: adjust fclose's position Wei,Jiangang
  0 siblings, 1 reply; 15+ messages in thread
From: Cyril Hrubis @ 2015-05-07 13:32 UTC (permalink / raw)
  To: Wei,Jiangang; +Cc: ltp-list

Hi!
> It will encounter resource leak for fp as the old flow,
> while fopen succeeds and the pointer para is NULL.
> This patch aims to avoid this resource leak.
> 
> Signed-off-by: Wei,Jiangang <weijg.fnst@cn.fujitsu.com>
> ---
>  testcases/kernel/sched/hyperthreading/ht_interrupt/ht_utils.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/testcases/kernel/sched/hyperthreading/ht_interrupt/ht_utils.c b/testcases/kernel/sched/hyperthreading/ht_interrupt/ht_utils.c
> index 1c33d0c..c845cf8 100644
> --- a/testcases/kernel/sched/hyperthreading/ht_interrupt/ht_utils.c
> +++ b/testcases/kernel/sched/hyperthreading/ht_interrupt/ht_utils.c
> @@ -30,8 +30,8 @@ int is_cmdline_para(const char *para)

Looking a the code it would be way easier to change it to:

	if (!para)
		return 0;

Then we will need to close the file only inside of the if condition:

	if ((fp = fopen("/proc/cmdline", "r")) != NULL)) {
		...
		fclose(fp);
	}

>  				return 1;
>  			}
>  		}
> -		fclose(fp);
>  	}
> +	if (fp != NULL)	fclose(fp);

This code is not following LKML coding style. You can use checkpath.pl
(distributed with Linux kernel sources) to check you patches before
submission.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [LTP] [PATCH v2 2/5] kernel/syscalls/ipc/lib: Don't allocate memory for getpwnam()
  2015-05-07 13:21   ` Cyril Hrubis
@ 2015-05-08  3:28     ` Wei,Jiangang
  0 siblings, 0 replies; 15+ messages in thread
From: Wei,Jiangang @ 2015-05-08  3:28 UTC (permalink / raw)
  To: ltp-list

The getpwnam() function returns a pointer for a passwd
structure. so Just need to declare a pointer to this structure,
not to allocate memory for it.

Signed-off-by: Wei,Jiangang <weijg.fnst@cn.fujitsu.com>
---
 testcases/kernel/syscalls/ipc/lib/libipc.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/testcases/kernel/syscalls/ipc/lib/libipc.c b/testcases/kernel/syscalls/ipc/lib/libipc.c
index f10e257..4de7faa 100644
--- a/testcases/kernel/syscalls/ipc/lib/libipc.c
+++ b/testcases/kernel/syscalls/ipc/lib/libipc.c
@@ -143,12 +143,6 @@ int getuserid(char *user)
 {
 	struct passwd *ent;
 
-	/* allocate some space for the passwd struct */
-	if ((ent = malloc(sizeof(struct passwd))) == NULL) {
-		tst_brkm(TBROK, cleanup, "couldn't allocate space for passwd"
-			 " structure");
-	}
-
 	/* get the uid value for the user */
 	if ((ent = getpwnam(user)) == NULL) {
 		tst_brkm(TBROK, cleanup, "Couldn't get password entry for %s",
-- 
1.9.3


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [LTP] [PATCH v2 3/5] kernel/mem/hugetlb/lib: Don't allocate memory for getpwnam()
  2015-05-07 13:21   ` Cyril Hrubis
@ 2015-05-08  3:31     ` Wei,Jiangang
  2015-05-08  8:33     ` [LTP] [PATCH v3 3/5] kernel/mem/hugetlb/lib: do refactor for getuserid Wei,Jiangang
  1 sibling, 0 replies; 15+ messages in thread
From: Wei,Jiangang @ 2015-05-08  3:31 UTC (permalink / raw)
  To: ltp-list

No need to allocate memory for a pointer,
which just used to store getpwnam()'s return.

Signed-off-by: Wei,Jiangang <weijg.fnst@cn.fujitsu.com>
---
 testcases/kernel/mem/hugetlb/lib/libipc.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/testcases/kernel/mem/hugetlb/lib/libipc.c b/testcases/kernel/mem/hugetlb/lib/libipc.c
index 21fd8da..1f16f22 100644
--- a/testcases/kernel/mem/hugetlb/lib/libipc.c
+++ b/testcases/kernel/mem/hugetlb/lib/libipc.c
@@ -85,10 +85,6 @@ int getuserid(char *user)
 {
 	struct passwd *ent;
 
-	ent = malloc(sizeof(struct passwd));
-	if (ent == NULL)
-		tst_brkm(TBROK | TERRNO, cleanup, "malloc ent");
-
 	ent = getpwnam(user);
 	if (ent == NULL)
 		tst_brkm(TBROK | TERRNO, cleanup, "getpwnam");
-- 
1.9.3


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [LTP] [PATCH v2 4/5] kernel/syscalls/dup2: optimize allocation and free
  2015-05-07 13:26   ` Cyril Hrubis
@ 2015-05-08  3:33     ` Wei,Jiangang
  0 siblings, 0 replies; 15+ messages in thread
From: Wei,Jiangang @ 2015-05-08  3:33 UTC (permalink / raw)
  To: ltp-list

Move the allocation and free to the cleanup and setup
respectively and ensure free fildes safely.

Signed-off-by: Wei,Jiangang <weijg.fnst@cn.fujitsu.com>
---
 testcases/kernel/syscalls/dup2/dup205.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/testcases/kernel/syscalls/dup2/dup205.c b/testcases/kernel/syscalls/dup2/dup205.c
index 14218dd..0b32453 100644
--- a/testcases/kernel/syscalls/dup2/dup205.c
+++ b/testcases/kernel/syscalls/dup2/dup205.c
@@ -40,6 +40,8 @@
 
 char *TCID = "dup205";
 int TST_TOTAL = 1;
+int *fildes;
+int min;
 int local_flag;
 
 #define PASSED 1
@@ -50,10 +52,8 @@ static void cleanup(void);
 
 int main(int ac, char *av[])
 {
-	int *fildes;
 	int ifile;
 	char pfilname[40];
-	int min;
 	int serrno;
 
 	int lc;
@@ -68,12 +68,6 @@ int main(int ac, char *av[])
 
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 
-		min = getdtablesize();	/* get number of files allowed open */
-
-		fildes = malloc((min + 10) * sizeof(int));
-		if (fildes == NULL)
-			tst_brkm(TBROK | TERRNO, cleanup, "malloc error");
-
 		sprintf(pfilname, "./dup205.%d\n", getpid());
 		unlink(pfilname);
 		serrno = 0;
@@ -125,9 +119,16 @@ int main(int ac, char *av[])
 static void setup(void)
 {
 	tst_tmpdir();
+
+	min = getdtablesize();	/* get number of files allowed open */
+	fildes = malloc((min + 10) * sizeof(int));
+	if (fildes == NULL)
+		tst_brkm(TBROK | TERRNO, cleanup, "malloc error");
 }
 
 static void cleanup(void)
 {
+	if (fildes != NULL)
+		free(fildes);
 	tst_rmdir();
 }
-- 
1.9.3


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [LTP] [PATCH v2 5/5] kernel/syscalls/fallocate: adjust fclose's position
  2015-05-07 13:32   ` Cyril Hrubis
@ 2015-05-08  3:39     ` Wei,Jiangang
  0 siblings, 0 replies; 15+ messages in thread
From: Wei,Jiangang @ 2015-05-08  3:39 UTC (permalink / raw)
  To: ltp-list

It will encounter resource leak for fp,
while fopen succeeds and the pointer para is NULL.
so need to move fclose out of if-block.

Signed-off-by: Wei,Jiangang <weijg.fnst@cn.fujitsu.com>
---
 testcases/kernel/sched/hyperthreading/ht_interrupt/ht_utils.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/sched/hyperthreading/ht_interrupt/ht_utils.c b/testcases/kernel/sched/hyperthreading/ht_interrupt/ht_utils.c
index 1c33d0c..bd2d373 100644
--- a/testcases/kernel/sched/hyperthreading/ht_interrupt/ht_utils.c
+++ b/testcases/kernel/sched/hyperthreading/ht_interrupt/ht_utils.c
@@ -30,8 +30,13 @@ int is_cmdline_para(const char *para)
 				return 1;
 			}
 		}
-		fclose(fp);
 	}
+	/* If fopen succeeds and the pointer para is NULL,
+	 * It won't enter the above if-block.
+	 * so need to close fp here.
+	 */
+	if (fp != NULL)
+		fclose(fp);
 
 	return 0;
 }
-- 
1.9.3


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [LTP] [PATCH v3 3/5] kernel/mem/hugetlb/lib: do refactor for getuserid
  2015-05-07 13:21   ` Cyril Hrubis
  2015-05-08  3:31     ` [LTP] [PATCH v2 " Wei,Jiangang
@ 2015-05-08  8:33     ` Wei,Jiangang
  1 sibling, 0 replies; 15+ messages in thread
From: Wei,Jiangang @ 2015-05-08  8:33 UTC (permalink / raw)
  To: ltp-list

* No need to allocate memory for getpwnam()'s return,
  So remove these codes.

* replace getpwnam() with getpwnam_r() that is thread-safe.

Signed-off-by: Wei,Jiangang <weijg.fnst@cn.fujitsu.com>
---
 testcases/kernel/mem/hugetlb/lib/libipc.c | 33 +++++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 8 deletions(-)

diff --git a/testcases/kernel/mem/hugetlb/lib/libipc.c b/testcases/kernel/mem/hugetlb/lib/libipc.c
index 21fd8da..91cc952 100644
--- a/testcases/kernel/mem/hugetlb/lib/libipc.c
+++ b/testcases/kernel/mem/hugetlb/lib/libipc.c
@@ -83,17 +83,34 @@ int getipckey(void)
  */
 int getuserid(char *user)
 {
-	struct passwd *ent;
+	struct passwd pwd;
+	struct passwd *result;
+	char *buf;
+	size_t buflen;
+	int s;
 
-	ent = malloc(sizeof(struct passwd));
-	if (ent == NULL)
-		tst_brkm(TBROK | TERRNO, cleanup, "malloc ent");
+	buflen = sysconf(_SC_GETPW_R_SIZE_MAX);
+	if (buflen == -1)
+		/* Should be more than enough */
+		buflen = 16384;
 
-	ent = getpwnam(user);
-	if (ent == NULL)
-		tst_brkm(TBROK | TERRNO, cleanup, "getpwnam");
+	buf = malloc(buflen);
+	if (buf == NULL)
+		tst_brkm(TBROK, NULL, "malloc failed.\n");
 
-	return ent->pw_uid;
+	s = getpwnam_r(user, &pwd, buf, buflen, &result);
+	if (result == NULL) {
+		free(buf);
+		if (s == 0) {
+			tst_brkm(TBROK, NULL, "Not found: %s", user);
+		} else {
+			tst_brkm(TBROK, NULL, "getpwnam_r failed. (%d) %s",
+				(s), strerror(s));
+		}
+	}
+	free(buf);
+
+	return pwd.pw_uid;
 }
 
 /*
-- 
1.9.3


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2015-05-08  8:34 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-06  7:26 [LTP] [PATCH 1/5] kernel/syscalls/mmap: remove unused cleanup() Wei,Jiangang
2015-05-06  7:26 ` [LTP] [PATCH 2/5] kernel/syscalls/ipc/lib: Don't allocate memory for getpwnam() Wei,Jiangang
2015-05-07 13:21   ` Cyril Hrubis
2015-05-08  3:28     ` [LTP] [PATCH v2 " Wei,Jiangang
2015-05-06  7:26 ` [LTP] [PATCH 3/5] kernel/mem/hugetlb/lib: " Wei,Jiangang
2015-05-07 13:21   ` Cyril Hrubis
2015-05-08  3:31     ` [LTP] [PATCH v2 " Wei,Jiangang
2015-05-08  8:33     ` [LTP] [PATCH v3 3/5] kernel/mem/hugetlb/lib: do refactor for getuserid Wei,Jiangang
2015-05-06  7:26 ` [LTP] [PATCH 4/5] kernel/syscalls/dup2: free fildes to avoid memory leak Wei,Jiangang
2015-05-07 13:26   ` Cyril Hrubis
2015-05-08  3:33     ` [LTP] [PATCH v2 4/5] kernel/syscalls/dup2: optimize allocation and free Wei,Jiangang
2015-05-06  7:26 ` [LTP] [PATCH 5/5] kernel/syscalls/fallocate: move fclose out of if-block Wei,Jiangang
2015-05-07 13:32   ` Cyril Hrubis
2015-05-08  3:39     ` [LTP] [PATCH v2 5/5] kernel/syscalls/fallocate: adjust fclose's position Wei,Jiangang
2015-05-07 13:22 ` [LTP] [PATCH 1/5] kernel/syscalls/mmap: remove unused cleanup() Cyril Hrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.