summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@kolpackov.net>2006-03-17 14:24:20 +0000
committerBoris Kolpackov <boris@kolpackov.net>2006-03-17 14:24:20 +0000
commit22886f8a74b5925030889fed52af5a8add5617d7 (patch)
treec28340c4ca8f7956e259f671b3202b6bf0874a35 /misc.c
parent50eb3cf5e5a8a68b68e966a6607f668f2c36191e (diff)
downloadgunmake-22886f8a74b5925030889fed52af5a8add5617d7.tar.gz
Fixed Savannah bug #16053.
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/misc.c b/misc.c
index 43df799..082bcc6 100644
--- a/misc.c
+++ b/misc.c
@@ -479,6 +479,32 @@ find_next_token (char **ptr, unsigned int *lengthptr)
return p;
}
+
+/* Allocate a new `struct dep' with all fields initialized to 0. */
+
+struct dep *
+alloc_dep ()
+{
+ struct dep *d = (struct dep *) xmalloc (sizeof (struct dep));
+ bzero ((char *) d, sizeof (struct dep));
+ return d;
+}
+
+
+/* Free `struct dep' along with `name' and `stem'. */
+
+void
+free_dep (struct dep *d)
+{
+ if (d->name != 0)
+ free (d->name);
+
+ if (d->stem != 0)
+ free (d->stem);
+
+ free ((char *)d);
+}
+
/* Copy a chain of `struct dep', making a new chain
with the same contents as the old one. */
@@ -493,8 +519,12 @@ copy_dep_chain (const struct dep *d)
{
c = (struct dep *) xmalloc (sizeof (struct dep));
bcopy ((char *) d, (char *) c, sizeof (struct dep));
+
if (c->name != 0)
c->name = xstrdup (c->name);
+ if (c->stem != 0)
+ c->stem = xstrdup (c->stem);
+
c->next = 0;
if (firstnew == 0)
firstnew = lastnew = c;
@@ -516,14 +546,12 @@ free_dep_chain (struct dep *d)
{
struct dep *df = d;
d = d->next;
-
- free (df->name);
- free ((char *)df);
+ free_dep (df);
}
}
/* Free a chain of `struct nameseq'. Each nameseq->name is freed
- as well. Can be used on `struct dep' chains.*/
+ as well. For `struct dep' chains use free_dep_chain. */
void
free_ns_chain (struct nameseq *n)