diff: fix a bug in my mdb changes

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Dec 18 01:58:33 AEDT 1998


Estimated hours taken: 0.5

runtime/mercury_wrapper.c:
	Fix a memory management bug in the handling of the `--mdb-*' options:
	we need to make a copy of the strings pointed to by `MR_optarg',
	because the memory that it points to gets deallocated when
	process_environment_options() returns.

Index: runtime/mercury_wrapper.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_wrapper.c,v
retrieving revision 1.29
diff -u -r1.29 mercury_wrapper.c
--- mercury_wrapper.c	1998/12/17 13:37:02	1.29
+++ mercury_wrapper.c	1998/12/17 14:53:49
@@ -38,6 +38,7 @@
 #include	"mercury_dummy.h"
 #include	"mercury_stack_layout.h"
 #include	"mercury_trace_base.h"
+#include	"mercury_memory.h"	/* for MR_copy_string() */
 
 /* global variables concerned with testing (i.e. not with the engine) */
 
@@ -608,24 +609,24 @@
 
 		case 'i':
 		case MR_MDB_IN:
-			MR_mdb_in_filename = MR_optarg;
+			MR_mdb_in_filename = MR_copy_string(MR_optarg);
 			break;
 
 		case 'o':
 		case MR_MDB_OUT:
-			MR_mdb_out_filename = MR_optarg;
+			MR_mdb_out_filename = MR_copy_string(MR_optarg);
 			break;
 
 		case 'e':
 		case MR_MDB_ERR:
-			MR_mdb_err_filename = MR_optarg;
+			MR_mdb_err_filename = MR_copy_string(MR_optarg);
 			break;
 
 		case 'm':
 		case MR_MDB_TTY:
-			MR_mdb_in_filename = MR_optarg;
-			MR_mdb_out_filename = MR_optarg;
-			MR_mdb_err_filename = MR_optarg;
+			MR_mdb_in_filename = MR_copy_string(MR_optarg);
+			MR_mdb_out_filename = MR_copy_string(MR_optarg);
+			MR_mdb_err_filename = MR_copy_string(MR_optarg);
 			break;
 
 		case 'a':
-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "Binaries may die
WWW: <http://www.cs.mu.oz.au/~fjh>  |   but source code lives forever"
PGP: finger fjh at 128.250.37.3        |     -- leaked Microsoft memo.



More information about the developers mailing list