diff --git a/driver/fcyc.c b/driver/fcyc.c
index 37a268522201742164e4f13e64c195d0525c1c9e..b8e41130cb8433e5ae4cfeeceac51e196dcf4556 100644
--- a/driver/fcyc.c
+++ b/driver/fcyc.c
@@ -250,6 +250,9 @@ void set_fcyc_epsilon(double epsilon_arg)
     epsilon = epsilon_arg;
 }
 
+void deinit_fcyc(void) {
+    free(cache_buf);
+}
 
 
 
diff --git a/driver/fcyc.h b/driver/fcyc.h
index d398278b47d60299c32f0114c98503730beeac60..3ecbb99b9d2df637f85ad7f0a38e8127b3447ad5 100644
--- a/driver/fcyc.h
+++ b/driver/fcyc.h
@@ -1,7 +1,7 @@
 /*
  * fcyc.h - prototypes for the routines in fcyc.c that estimate the
  *     time in CPU cycles used by a test function f
- * 
+ *
  * Copyright (c) 2002, R. Bryant and D. O'Hallaron, All rights reserved.
  * May not be used, modified, or copied without permission.
  *
@@ -14,55 +14,55 @@ typedef void (*test_funct)(void *);
 double fcyc(test_funct f, void* argp);
 
 /*********************************************************
- * Set the various parameters used by measurement routines 
+ * Set the various parameters used by measurement routines
  *********************************************************/
 
-/* 
- * set_fcyc_clear_cache - When set, will run code to clear cache 
- *     before each measurement. 
+/*
+ * set_fcyc_clear_cache - When set, will run code to clear cache
+ *     before each measurement.
  *     Default = 0
  */
 void set_fcyc_clear_cache(int clear);
 
-/* 
- * set_fcyc_cache_size - Set size of cache to use when clearing cache 
+/*
+ * set_fcyc_cache_size - Set size of cache to use when clearing cache
  *     Default = 1<<19 (512KB)
  */
 void set_fcyc_cache_size(int bytes);
 
-/* 
- * set_fcyc_cache_block - Set size of cache block 
+/*
+ * set_fcyc_cache_block - Set size of cache block
  *     Default = 32
  */
 void set_fcyc_cache_block(int bytes);
 
-/* 
- * set_fcyc_compensate- When set, will attempt to compensate for 
- *     timer interrupt overhead 
+/*
+ * set_fcyc_compensate- When set, will attempt to compensate for
+ *     timer interrupt overhead
  *     Default = 0
  */
 void set_fcyc_compensate(int compensate_arg);
 
-/* 
+/*
  * set_fcyc_k - Value of K in K-best measurement scheme
  *     Default = 3
  */
 void set_fcyc_k(int k);
 
-/* 
- * set_fcyc_maxsamples - Maximum number of samples attempting to find 
+/*
+ * set_fcyc_maxsamples - Maximum number of samples attempting to find
  *     K-best within some tolerance.
  *     When exceeded, just return best sample found.
  *     Default = 20
  */
 void set_fcyc_maxsamples(int maxsamples_arg);
 
-/* 
+/*
  * set_fcyc_epsilon - Tolerance required for K-best
  *     Default = 0.01
  */
 void set_fcyc_epsilon(double epsilon_arg);
 
-
+void deinit_fcyc(void);
 
 
diff --git a/driver/fsecs.c b/driver/fsecs.c
index 41908a68080ee4384830f29637d5a4ae65740a05..dad84bd49adefc9bc9e1153adf6e0cb2c3e5e92e 100644
--- a/driver/fsecs.c
+++ b/driver/fsecs.c
@@ -54,4 +54,7 @@ double fsecs(fsecs_test_funct f, void *argp)
 #endif
 }
 
+void deinit_fsecs(void) {
+    deinit_fcyc();
+}
 
diff --git a/driver/fsecs.h b/driver/fsecs.h
index 59e095dba1901425a159b66249c6b40eb7d5cad4..321d78fbb8d899f00ff437d11ad9eaba43e30291 100644
--- a/driver/fsecs.h
+++ b/driver/fsecs.h
@@ -2,3 +2,4 @@ typedef void (*fsecs_test_funct)(void *);
 
 void init_fsecs(void);
 double fsecs(fsecs_test_funct f, void *argp);
+void deinit_fsecs(void);
diff --git a/driver/mdriver.c b/driver/mdriver.c
index 2b233ef23d2725f8a49292f8f2995687453a0243..f614db35d38ec10a4ceaab400237cbc938566595 100644
--- a/driver/mdriver.c
+++ b/driver/mdriver.c
@@ -86,7 +86,6 @@ typedef struct {
  */
 typedef struct {
 	trace_t *trace;
-	range_t *ranges;
 } speed_t;
 
 /* Summarizes the important stats for some malloc function on some trace */
@@ -184,9 +183,10 @@ static void app_error(const char *fmt, ...)
    num_tracefiles, if there's a timeout) */
 static void run_tests(int num_tracefiles, const char *tracedir,
 		char **tracefiles,
-		stats_t *mm_stats, range_t *ranges, speed_t *speed_params) {
+		stats_t *mm_stats, speed_t *speed_params) {
 	volatile int i;
 
+	range_t *ranges = NULL; /* keeps track of block extents for one trace */
 	for (i=0; i < num_tracefiles; i++) {
 		trace_t *trace;
 		trace = read_trace(&mm_stats[i], tracedir, tracefiles[i]);
@@ -195,6 +195,7 @@ static void run_tests(int num_tracefiles, const char *tracedir,
 		if (verbose > 1)
 			printf("Checking mm_malloc for correctness, ");
 		mm_stats[i].valid = eval_mm_valid(trace, &ranges);
+		clear_ranges(&ranges);
 
 		if (onetime_flag) {
 			free_trace(trace);
@@ -205,7 +206,6 @@ static void run_tests(int num_tracefiles, const char *tracedir,
 				printf("efficiency, ");
 			mm_stats[i].util = eval_mm_util(trace, i);
 			speed_params->trace = trace;
-			speed_params->ranges = ranges;
 			if (verbose > 1)
 				printf("and performance.\n");
 			mm_stats[i].secs = fsecs(eval_mm_speed, speed_params);
@@ -224,7 +224,6 @@ int main(int argc, char **argv)
 	char **tracefiles = NULL;  /* null-terminated array of trace file names */
 	int num_tracefiles = 0;    /* the number of traces in that array */
 
-	range_t *ranges = NULL;    /* keeps track of block extents for one trace */
 	stats_t *libc_stats = NULL;/* libc stats for each trace */
 	stats_t *mm_stats = NULL;  /* mm (i.e. student) stats for each trace */
 	speed_t speed_params;      /* input parameters to the xx_speed routines */
@@ -349,9 +348,10 @@ int main(int argc, char **argv)
 	/* Initialize the simulated memory system in memlib.c */
 	mem_init();
 
-	run_tests(num_tracefiles, tracedir, tracefiles, mm_stats,
-			ranges, &speed_params);
+	run_tests(num_tracefiles, tracedir, tracefiles, mm_stats, &speed_params);
 
+	mem_deinit();
+	deinit_fsecs();
 
 	/* Display the mm results in a compact table */
 	if (verbose) {
@@ -369,6 +369,13 @@ int main(int argc, char **argv)
 		}
 	}
 
+	if (tracefiles != default_tracefiles) {
+		for (i = 0; i < num_tracefiles; i++) {
+			free(tracefiles[i]);
+		}
+		free(tracefiles);
+	}
+
 	/*
 	 * Accumulate the aggregate statistics for the student's mm package
 	 */
@@ -384,6 +391,7 @@ int main(int argc, char **argv)
 		if (mm_stats[i].valid)
 			numcorrect++;
 	}
+	free(mm_stats);
 	if(weight == 0)
 		avg_mm_util = 0;
 	else
@@ -769,7 +777,6 @@ static int eval_mm_valid(trace_t *trace, range_t **ranges)
 
 	/* Reset the heap and free any records in the range list */
 	mem_reset_brk();
-	clear_ranges(ranges);
 	reinit_trace(trace);
 
 	/* Call the mm package's init function */