summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2006-02-20 02:14:00 +0000
committerPaul Smith <psmith@gnu.org>2006-02-20 02:14:00 +0000
commit6e0527913c6724fa92e2135de991e27df54c4289 (patch)
treec9e4c448ae4476e5ef81ca5a5ca8feb344e519c7
parentbde826b18aeb6fd3c9de7a7733d1e163efde90e1 (diff)
downloadgunmake-6e0527913c6724fa92e2135de991e27df54c4289.tar.gz
- Memory cleanups, found with valgrind.
- Fix handling of special targets like .SUFFIX for VMS insensitive targets. - Don't make temporary batch files for -n. Make sure batch files are created in text mode.
-rw-r--r--ChangeLog22
-rw-r--r--commands.c6
-rw-r--r--expand.c16
-rw-r--r--file.c54
-rw-r--r--implicit.c13
-rw-r--r--job.c7
6 files changed, 71 insertions, 47 deletions
diff --git a/ChangeLog b/ChangeLog
index 07d1e52..969df36 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2006-02-19 Paul D. Smith <psmith@gnu.org>
+
+ * commands.c (set_file_variables): Realloc, not malloc, the static
+ string values to avoid memory leaks.
+
+ * expand.c (recursively_expand_for_file): Only set reading_file to
+ an initialized value.
+
+ * implicit.c (pattern_search): We need to make a copy of the stem
+ if we get it from an intermediate dep, since those get freed.
+
+ * file.c (lookup_file) [VMS]: Don't lowercase special targets that
+ begin with ".".
+ (enter_file) [VMS]: Ditto.
+ Patch provided by Hartmut Becker <Hartmut.Becker@hp.com>.
+
+2006-02-18 Eli Zaretskii <eliz@gnu.org>
+
+ * job.c (construct_command_argv_internal): Don't create a temporary
+ script/batch file if we are under -n. Call _setmode to switch the
+ script file stream to text mode.
+
2006-02-17 Paul D. Smith <psmith@gnu.org>
* variable.c (merge_variable_set_lists): Don't try to merge the
diff --git a/commands.c b/commands.c
index 691eb35..a0a7c5c 100644
--- a/commands.c
+++ b/commands.c
@@ -157,7 +157,7 @@ set_file_variables (struct file *file)
plus_len++;
if (plus_len > plus_max)
- plus_value = (char *) xmalloc (plus_max = plus_len);
+ plus_value = xrealloc (plus_value, plus_max = plus_len);
cp = plus_value;
qmark_len = plus_len + 1; /* Will be this or less. */
@@ -206,11 +206,11 @@ set_file_variables (struct file *file)
cp = caret_value = plus_value; /* Reuse the buffer; it's big enough. */
if (qmark_len > qmark_max)
- qmark_value = (char *) xmalloc (qmark_max = qmark_len);
+ qmark_value = xrealloc (qmark_value, qmark_max = qmark_len);
qp = qmark_value;
if (bar_len > bar_max)
- bar_value = (char *) xmalloc (bar_max = bar_len);
+ bar_value = xrealloc (bar_value, bar_max = bar_len);
bp = bar_value;
for (d = file->deps; d != 0; d = d->next)
diff --git a/expand.c b/expand.c
index d25afef..39f0d19 100644
--- a/expand.c
+++ b/expand.c
@@ -113,11 +113,18 @@ recursively_expand_for_file (struct variable *v, struct file *file)
expanding_var = &this_var;
}
+ /* If we have no other file-reading context, use the variable's context. */
+ if (!reading_file)
+ {
+ set_reading = 1;
+ reading_file = &v->fileinfo;
+ }
+
if (v->expanding)
{
if (!v->exp_count)
/* Expanding V causes infinite recursion. Lose. */
- fatal (this_var,
+ fatal (*expanding_var,
_("Recursive variable `%s' references itself (eventually)"),
v->name);
--v->exp_count;
@@ -129,13 +136,6 @@ recursively_expand_for_file (struct variable *v, struct file *file)
current_variable_set_list = file->variables;
}
- /* If we have no other file-reading context, use the variable's context. */
- if (!reading_file)
- {
- set_reading = 1;
- reading_file = this_var;
- }
-
v->expanding = 1;
if (v->append)
value = allocated_variable_append (v);
diff --git a/file.c b/file.c
index 0d5e9da..a0e8222 100644
--- a/file.c
+++ b/file.c
@@ -88,14 +88,15 @@ lookup_file (char *name)
on the command line. */
#ifdef VMS
# ifndef WANT_CASE_SENSITIVE_TARGETS
- {
- register char *n;
- lname = (char *) malloc (strlen (name) + 1);
- for (n = name, ln = lname; *n != '\0'; ++n, ++ln)
- *ln = isupper ((unsigned char)*n) ? tolower ((unsigned char)*n) : *n;
- *ln = '\0';
- name = lname;
- }
+ if (*name != '.')
+ {
+ register char *n;
+ lname = (char *) malloc (strlen (name) + 1);
+ for (n = name, ln = lname; *n != '\0'; ++n, ++ln)
+ *ln = isupper ((unsigned char)*n) ? tolower ((unsigned char)*n) : *n;
+ *ln = '\0';
+ name = lname;
+ }
# endif
while (name[0] == '[' && name[1] == ']' && name[2] != '\0')
@@ -124,7 +125,8 @@ lookup_file (char *name)
file_key.hname = name;
f = (struct file *) hash_find_item (&files, &file_key);
#if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
- free (lname);
+ if (*name != '.')
+ free (lname);
#endif
return f;
}
@@ -143,22 +145,23 @@ enter_file (char *name)
assert (*name != '\0');
#if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
- {
- register char *n;
- lname = (char *) malloc (strlen (name) + 1);
- for (n = name, ln = lname; *n != '\0'; ++n, ++ln)
- {
- if (isupper ((unsigned char)*n))
- *ln = tolower ((unsigned char)*n);
- else
- *ln = *n;
- }
+ if (*name != '.')
+ {
+ register char *n;
+ lname = (char *) malloc (strlen (name) + 1);
+ for (n = name, ln = lname; *n != '\0'; ++n, ++ln)
+ {
+ if (isupper ((unsigned char)*n))
+ *ln = tolower ((unsigned char)*n);
+ else
+ *ln = *n;
+ }
- *ln = 0;
- /* Creates a possible leak, old value of name is unreachable, but I
- currently don't know how to fix it. */
- name = lname;
- }
+ *ln = 0;
+ /* Creates a possible leak, old value of name is unreachable, but I
+ currently don't know how to fix it. */
+ name = lname;
+ }
#endif
file_key.hname = name;
@@ -167,7 +170,8 @@ enter_file (char *name)
if (! HASH_VACANT (f) && !f->double_colon)
{
#if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
- free(lname);
+ if (*name != '.')
+ free (lname);
#endif
return f;
}
diff --git a/implicit.c b/implicit.c
index d7c140a..054b71a 100644
--- a/implicit.c
+++ b/implicit.c
@@ -90,14 +90,9 @@ free_idep_chain (struct idep *p)
free (p->name);
f = p->intermediate_file;
- if (f != 0)
- {
- /* if (f->variables)
- free_variable_set (f->variables); */
- if (f->stem < f->name
- || f->stem > f->name + strlen (f->name))
- free (f->stem);
- }
+ if (f != 0
+ && (f->stem < f->name || f->stem > f->name + strlen (f->name)))
+ free (f->stem);
free (p);
}
@@ -841,7 +836,7 @@ pattern_search (struct file *file, int archive,
f->deps = imf->deps;
f->cmds = imf->cmds;
- f->stem = imf->stem;
+ f->stem = xstrdup (imf->stem);
f->also_make = imf->also_make;
f->is_target = 1;
diff --git a/job.c b/job.c
index 34f359d..3ef4c75 100644
--- a/job.c
+++ b/job.c
@@ -2770,6 +2770,8 @@ construct_command_argv_internal (char *line, char **restp, char *shell,
/* Some shells do not work well when invoked as 'sh -c xxx' to run a
command line (e.g. Cygnus GNUWIN32 sh.exe on WIN32 systems). In these
cases, run commands via a script file. */
+ if (just_print_flag)
+ ; /* Do nothing here. */
if ((no_default_sh_exe || batch_mode_shell) && batch_filename_ptr) {
int temp_fd;
FILE* batch = NULL;
@@ -2784,8 +2786,9 @@ construct_command_argv_internal (char *line, char **restp, char *shell,
*batch_filename_ptr));
/* Create a FILE object for the batch file, and write to it the
- commands to be executed. */
- batch = _fdopen (temp_fd, "w");
+ commands to be executed. Put the batch file in TEXT mode. */
+ _setmode (temp_fd, _O_TEXT);
+ batch = _fdopen (temp_fd, "wt");
if (!unixy_shell)
fputs ("@echo off\n", batch);
fputs (command_ptr, batch);