Re: rtcwake: valgrind reports mem leak

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, 2011-02-27 at 17:37 +0100, Marek Otahal wrote:
> Hi list, 
> I'm learning valgrind, ran it against rtcwake and got 1 leaked block. 
> Attaching the output so you can have a look. As I say, I'm just learning so if 
> it's a false positive, I'm sorry. 

Not a false positive, strdup allocates memory which is not being freed
by the programmer. We don't really care about these kind of leaks
because the OS frees the program memory anyways, but for correctness
here's a patch that would solve it.

From: Davidlohr Bueso <dave@xxxxxxx>
Date: Sun, 27 Feb 2011 14:40:45 -0300
Subject: [PATCH] rtcwake: do not duplicate argument strings.

This is not necessary and prevents memory leaks.

Reported-by: Marek Otahal <markotahal@xxxxxxxxx>
Signed-off-by: Davidlohr Bueso <dave@xxxxxxx>
---
 sys-utils/rtcwake.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c
index da8c085..09ccbea 100644
--- a/sys-utils/rtcwake.c
+++ b/sys-utils/rtcwake.c
@@ -380,7 +380,7 @@ int main(int argc, char **argv)
 			break;
 
 		case 'd':
-			devname = strdup(optarg);
+			devname = optarg;
 			break;
 
 		case 'l':
@@ -405,7 +405,7 @@ int main(int argc, char **argv)
 					|| strcmp(optarg, "disable") == 0
 					|| strcmp(optarg, "show") == 0
 			   ) {
-				suspend = strdup(optarg);
+				suspend = optarg;
 				break;
 			}
 
-- 
1.7.1



--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux