Index: branches/stable/mondo/src/common/libmondo-devices.c
===================================================================
--- branches/stable/mondo/src/common/libmondo-devices.c (revision 1130)
+++ branches/stable/mondo/src/common/libmondo-devices.c (revision 1156)
@@ -2115,17 +2052,18 @@
 void sensibly_set_tmpdir_and_scratchdir(struct s_bkpinfo *bkpinfo)
 {
-	char *tmp, *command, *sz;
-
-	malloc_string(tmp);
+	char *tmp = NULL;
+	char *command = NULL;
+	char *sz = NULL;
+	int i = 0;
+
 	malloc_string(command);
-	malloc_string(sz);
 	assert(bkpinfo != NULL);
 
 #ifdef __FreeBSD__
-	strcpy(tmp,
+	mr_asprintf(&tmp,
 		   call_program_and_get_last_line_of_output
 		   ("df -m -P -t nonfs,msdosfs,ntfs,smbfs,smb,cifs,afs,mvfs | tr -s '\t' ' ' | grep -vE \"none|Filesystem\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"));
 #else
-	strcpy(tmp,
+	mr_asprintf(&tmp,
 		   call_program_and_get_last_line_of_output
 		   ("df -m -P -x nfs -x vfat -x ntfs -x smbfs -x smb -x cifs -x afs -x mvfs | sed 's/                  /devdev/' | tr -s '\t' ' ' | grep -vE \"none|Filesystem|/dev/shm\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"));
@@ -2133,17 +2071,16 @@
 
 	if (tmp[0] != '/') {
-		strcpy(sz, tmp);
-		strcpy(tmp, "/");
-		strcat(tmp, sz);
+		mr_asprintf(&sz, "/%s", tmp);
+		mr_free(tmp);
+		tmp = sz;
 	}
 	if (!tmp[0]) {
 		fatal_error("I couldn't figure out the tempdir!");
 	}
-	sprintf(bkpinfo->tmpdir, "%s/tmp.mondo.%d", tmp,
-			(int) (random() % 32768));
+	i = (int) (random() % 32768);
+	sprintf(bkpinfo->tmpdir, "%s/tmp.mondo.%d", tmp, i);
 	log_it("bkpinfo->tmpdir is being set to %s", bkpinfo->tmpdir);
 
-	sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%d", tmp,
-			(int) (random() % 32768));
+	sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%d", tmp, i);
 	log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir);
 
@@ -2151,9 +2088,9 @@
 			bkpinfo->scratchdir);
 
-	sprintf(command, "rm -Rf %s/tmp.mondo.* %s/mondo.scratch.*", tmp, tmp);
+	mr_asprintf(&command, "rm -Rf %s/tmp.mondo.* %s/mondo.scratch.*", tmp, tmp);
+	mr_free(tmp);
+
 	paranoid_system(command);
-	mr_free(tmp);
 	mr_free(command);
-	mr_free(sz);
 }
 
@@ -2172,12 +2109,10 @@
 bool set_dev_to_this_if_rx_OK(char *output, char *dev)
 {
-	char *command;
-
-	malloc_string(command);
+	char *command = NULL;
+
 	if (!dev || dev[0] == '\0') {
 		output[0] = '\0';
 		return (FALSE);
 	}
-//  assert_string_is_neither_NULL_nor_zerolength(dev);
 	mr_msg(10, "Injecting %s", dev);
 	inject_device(dev);
@@ -2186,5 +2121,5 @@
 		return (FALSE);
 	}
-	sprintf(command, "dd bs=%ld count=1 if=%s of=/dev/null &> /dev/null",
+	mr_asprintf(&command, "dd bs=%ld count=1 if=%s of=/dev/null &> /dev/null",
 			512L, dev);
 	if (!run_program_and_log_output(command, FALSE)
@@ -2192,8 +2127,10 @@
 		strcpy(output, dev);
 		mr_msg(4, "Found it - %s", dev);
+		mr_free(command);
 		return (TRUE);
 	} else {
 		output[0] = '\0';
 		mr_msg(4, "It's not %s", dev);
+		mr_free(command);
 		return (FALSE);
 	}
@@ -2211,20 +2148,14 @@
 {
 	int cd_number = -1;
-	char *mountdev;
-	char *tmp;
-
-	malloc_string(mountdev);
-	malloc_string(tmp);
+	char *mountdev = NULL;
+	char *tmp = NULL;
+	char *tmp1 = NULL;
+
 	assert(bkpinfo != NULL);
-//  log_it("Asking what_number_cd_is_this");
 	if (g_ISO_restore_mode) {
-		sprintf(tmp, "mount | grep iso9660 | awk '{print $3;}'");
-//      log_it("tmp = %s", tmp);
-
-		strcpy(mountdev, call_program_and_get_last_line_of_output(tmp));
-		strcat(mountdev, "/archives/THIS-CD-NUMBER");
-//      log_it("mountdev = %s", mountdev);
+		mr_asprintf(&tmp, "mount | grep iso9660 | awk '{print $3;}'");
+
+		mr_asprintf(&mountdev, "%s/archives/THIS-CD-NUMBER", call_program_and_get_last_line_of_output(tmp));
 		cd_number = atoi(last_line_of_file(mountdev));
-//      log_it("cd_number = %d", cd_number);
 		mr_free(mountdev);
 		mr_free(tmp);
@@ -2232,5 +2163,5 @@
 	}
 
-	strcpy(mountdev, bkpinfo->media_device);
+	mr_asprintf(&mountdev, bkpinfo->media_device);
 	if (!mountdev[0]) {
 		log_it
@@ -2243,7 +2174,5 @@
 	cd_number =
 		atoi(last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER"));
-//  log_it("cd_number..later.. = %d", cd_number);
 	mr_free(mountdev);
-	mr_free(tmp);
 	return (cd_number);
 }
@@ -2499,8 +2428,5 @@
 	char *command = NULL;
 	char *fdisk = NULL;
-#ifdef __IA64__
-	struct stat buf;
-#endif
-	malloc_string(tmp);
+
 	mr_msg(0, "Looking for partition table format type");
 	mr_asprintf(&fdisk, "/sbin/parted2fdisk");
@@ -2509,5 +2435,5 @@
 	mr_free(fdisk);
 
-	strcpy(tmp, call_program_and_get_last_line_of_output(command));
+	mr_asprintf(&tmp, call_program_and_get_last_line_of_output(command));
 	mr_free(command);
 
@@ -2517,6 +2443,6 @@
 		strcpy(output, "GPT");
 	}
+	mr_free(tmp);
 	mr_msg(0, "Found %s partition table format type", output);
-	mr_free(tmp);
 	return(output);
 }
