Index: lib/ipmi_main.c
===================================================================
RCS file: /cvsroot/ipmitool/ipmitool/lib/ipmi_main.c,v
retrieving revision 1.36
diff -u -r1.36 ipmi_main.c
--- lib/ipmi_main.c	17 Oct 2012 05:03:45 -0000	1.36
+++ lib/ipmi_main.c	10 Jan 2013 20:36:17 -0000
@@ -370,7 +370,8 @@
 	int retry = 0;
 	uint32_t timeout = 0;
 	int authtype = -1;
-	char * tmp = NULL;
+	char * tmp_pass = NULL;
+	char * tmp_env = NULL;
 	char * hostname = NULL;
 	char * username = NULL;
 	char * password = NULL;
@@ -396,6 +397,8 @@
 	{
 		switch (argflag) {
 		case 'I':
+			if (intfname)
+				free(intfname);
 			intfname = strdup(optarg);
 			if (intfname == NULL) {
 				lprintf(LOG_ERR, "%s: malloc failure", progname);
@@ -473,6 +476,8 @@
 			csv_output = 1;
 			break;
 		case 'H':
+			if (hostname)
+				free(hostname);
 			hostname = strdup(optarg);
 			if (hostname == NULL) {
 				lprintf(LOG_ERR, "%s: malloc failure", progname);
@@ -489,14 +494,15 @@
 			break;
 		case 'a':
 #ifdef HAVE_GETPASSPHRASE
-			tmp = getpassphrase("Password: ");
+			tmp_pass = getpassphrase("Password: ");
 #else
-			tmp = getpass("Password: ");
+			tmp_pass = getpass("Password: ");
 #endif
-			if (tmp != NULL) {
+			if (tmp_pass != NULL) {
 				if (password)
 					free(password);
-				password = strdup(tmp);
+				password = strdup(tmp_pass);
+				free(tmp_pass);
 				if (password == NULL) {
 					lprintf(LOG_ERR, "%s: malloc failure", progname);
 					goto out_free;
@@ -504,6 +510,8 @@
 			}
 			break;
 		case 'k':
+			if (kgkey)
+				free(kgkey);
 			kgkey = strdup(optarg);
 			if (kgkey == NULL) {
 				lprintf(LOG_ERR, "%s: malloc failure", progname);
@@ -511,10 +519,10 @@
 			}
 			break;
 		case 'K':
-			if ((tmp = getenv("IPMI_KGKEY"))) {
+			if ((tmp_env = getenv("IPMI_KGKEY"))) {
 				if (kgkey)
 					free(kgkey);
-				kgkey = strdup(tmp);
+				kgkey = strdup(tmp_env);
 				if (kgkey == NULL) {
 					lprintf(LOG_ERR, "%s: malloc failure", progname);
 					goto out_free;
@@ -524,6 +532,8 @@
 			}
 			break;
 		case 'y':
+			if (kgkey)
+				free(kgkey);
 			kgkey = ipmi_parse_hex(optarg);
 			if (kgkey == NULL) {
 				goto out_free;
@@ -531,14 +541,15 @@
 			break;
 		case 'Y':
 #ifdef HAVE_GETPASSPHRASE
-			tmp = getpassphrase("Key: ");
+			tmp_pass = getpassphrase("Key: ");
 #else
-			tmp = getpass("Key: ");
+			tmp_pass = getpass("Key: ");
 #endif
-			if (tmp != NULL) {
+			if (tmp_pass != NULL) {
 				if (kgkey)
 					free(kgkey);
-				kgkey = strdup(tmp);
+				kgkey = strdup(tmp_pass);
+				free(tmp_pass);
 				if (kgkey == NULL) {
 					lprintf(LOG_ERR, "%s: malloc failure", progname);
 					goto out_free;
@@ -546,6 +557,8 @@
 			}
 			break;
 		case 'U':
+			if (username)
+				free(username);
 			if (strlen(optarg) > 16) {
 				lprintf(LOG_ERR, "Username is too long (> 16 bytes)");
 				goto out_free;
@@ -557,6 +570,8 @@
 			}
 			break;
 		case 'S':
+			if (sdrcache)
+				free(sdrcache);
 			sdrcache = strdup(optarg);
 			if (sdrcache == NULL) {
 				lprintf(LOG_ERR, "%s: malloc failure", progname);
@@ -565,6 +580,8 @@
 			break;
 #ifdef ENABLE_ALL_OPTIONS
 		case 'o':
+			if (oemtype)
+				free(oemtype);
 			oemtype = strdup(optarg);
 			if (oemtype == NULL) {
 				lprintf(LOG_ERR, "%s: malloc failure", progname);
@@ -579,10 +596,14 @@
 			break;
 		case 'g':
 			/* backwards compatible oem hack */
+			if (oemtype)
+				free(oemtype);
 			oemtype = strdup("intelwv2");
 			break;
 		case 's':
 			/* backwards compatible oem hack */
+			if (oemtype)
+				free(oemtype);
 			oemtype = strdup("supermicro");
 			break;
 		case 'P':
@@ -599,19 +620,19 @@
 			memset(optarg, 'X', i);
 			break;
 		case 'E':
-			if ((tmp = getenv("IPMITOOL_PASSWORD"))) {
+			if ((tmp_env = getenv("IPMITOOL_PASSWORD"))) {
 				if (password)
 					free(password);
-				password = strdup(tmp);
+				password = strdup(tmp_env);
 				if (password == NULL) {
 					lprintf(LOG_ERR, "%s: malloc failure", progname);
 					goto out_free;
 				}
 			}
-			else if ((tmp = getenv("IPMI_PASSWORD"))) {
+			else if ((tmp_env = getenv("IPMI_PASSWORD"))) {
 				if (password)
 					free(password);
-				password = strdup(tmp);
+				password = strdup(tmp_env);
 				if (password == NULL) {
 					lprintf(LOG_ERR, "%s: malloc failure", progname);
 					goto out_free;
@@ -681,6 +702,8 @@
 			sol_escape_char = optarg[0];
 			break;
 		case 'O':
+			if (seloem)
+				free(seloem);
 			seloem = strdup(optarg);
 			if (seloem == NULL) {
 				lprintf(LOG_ERR, "%s: malloc failure", progname);
@@ -735,12 +758,13 @@
 	if (hostname != NULL && password == NULL &&
 			(authtype != IPMI_SESSION_AUTHTYPE_NONE || authtype < 0)) {
 #ifdef HAVE_GETPASSPHRASE
-		tmp = getpassphrase("Password: ");
+		tmp_pass = getpassphrase("Password: ");
 #else
-		tmp = getpass("Password: ");
+		tmp_pass = getpass("Password: ");
 #endif
-		if (tmp != NULL) {
-			password = strdup(tmp);
+		if (tmp_pass != NULL) {
+			password = strdup(tmp_pass);
+			free(tmp_pass);
 			if (password == NULL) {
 				lprintf(LOG_ERR, "%s: malloc failure", progname);
 				goto out_free;
