Commit bef985f3 by Neil Booth Committed by Neil Booth

cpphash.c (_cpp_destroy_hashtable): Use ht_destroy.

	* cpphash.c (_cpp_destroy_hashtable): Use ht_destroy.
	* cpphash.h (CPP_IN_SYSTEM_HEADER): Fix.
	(struct cpp_pool): New member first.
	* cppinit.c (append_include_chain): Plug memory leaks.
	* cpplib.c (cpp_register_pragma, cpp_register_pragma_space):
	Allocate pragma structures from the (aligned) macro pool to
	avoid leaking memory.
	* cpplex.c (_cpp_init_pool, _cpp_free_pool): Use pool->first
	so we don't leak memory.
	* hashtable.c (ht_destroy): New.
	* hashtable.h (ht_destroy): New.

From-SVN: r44794
parent 4d5f3fbd
2001-08-11 Neil Booth <neil@daikokuya.demon.co.uk> 2001-08-11 Neil Booth <neil@daikokuya.demon.co.uk>
* cpphash.c (_cpp_destroy_hashtable): Use ht_destroy.
* cpphash.h (CPP_IN_SYSTEM_HEADER): Fix.
(struct cpp_pool): New member first.
* cppinit.c (append_include_chain): Plug memory leaks.
* cpplib.c (cpp_register_pragma, cpp_register_pragma_space):
Allocate pragma structures from the (aligned) macro pool to
avoid leaking memory.
* cpplex.c (_cpp_init_pool, _cpp_free_pool): Use pool->first
so we don't leak memory.
* hashtable.c (ht_destroy): New.
* hashtable.h (ht_destroy): New.
2001-08-11 Neil Booth <neil@daikokuya.demon.co.uk>
Franz Sirl <Franz.Sirl-kernel@lauterbach.com> Franz Sirl <Franz.Sirl-kernel@lauterbach.com>
* c-lex.c (map): Make const. * c-lex.c (map): Make const.
......
...@@ -73,7 +73,7 @@ _cpp_destroy_hashtable (pfile) ...@@ -73,7 +73,7 @@ _cpp_destroy_hashtable (pfile)
{ {
if (pfile->our_hashtable) if (pfile->our_hashtable)
{ {
free (pfile->hash_table); ht_destroy (pfile->hash_table);
obstack_free (&pfile->hash_ob, 0); obstack_free (&pfile->hash_ob, 0);
} }
} }
......
...@@ -66,7 +66,7 @@ struct cpp_chunk ...@@ -66,7 +66,7 @@ struct cpp_chunk
typedef struct cpp_pool cpp_pool; typedef struct cpp_pool cpp_pool;
struct cpp_pool struct cpp_pool
{ {
struct cpp_chunk *cur, *locked; struct cpp_chunk *cur, *locked, *first;
unsigned char *pos; /* Current position. */ unsigned char *pos; /* Current position. */
unsigned int align; unsigned int align;
unsigned int locks; unsigned int locks;
...@@ -368,7 +368,7 @@ extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1]; ...@@ -368,7 +368,7 @@ extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
/* Macros. */ /* Macros. */
#define CPP_PRINT_DEPS(PFILE) CPP_OPTION (PFILE, print_deps) #define CPP_PRINT_DEPS(PFILE) CPP_OPTION (PFILE, print_deps)
#define CPP_IN_SYSTEM_HEADER(PFILE) (pfile->map && pfile->map->sysp) #define CPP_IN_SYSTEM_HEADER(PFILE) ((PFILE)->map && (PFILE)->map->sysp)
#define CPP_PEDANTIC(PF) CPP_OPTION (PF, pedantic) #define CPP_PEDANTIC(PF) CPP_OPTION (PF, pedantic)
#define CPP_WTRADITIONAL(PF) CPP_OPTION (PF, warn_traditional) #define CPP_WTRADITIONAL(PF) CPP_OPTION (PF, warn_traditional)
......
...@@ -197,8 +197,8 @@ path_include (pfile, list, path) ...@@ -197,8 +197,8 @@ path_include (pfile, list, path)
while (1); while (1);
} }
/* Append DIR to include path PATH. DIR must be permanently allocated /* Append DIR to include path PATH. DIR must be allocated on the
and writable. */ heap; this routine takes responsibility for freeing it. */
static void static void
append_include_chain (pfile, dir, path, cxx_aware) append_include_chain (pfile, dir, path, cxx_aware)
cpp_reader *pfile; cpp_reader *pfile;
...@@ -212,8 +212,12 @@ append_include_chain (pfile, dir, path, cxx_aware) ...@@ -212,8 +212,12 @@ append_include_chain (pfile, dir, path, cxx_aware)
unsigned int len; unsigned int len;
if (*dir == '\0') if (*dir == '\0')
dir = xstrdup ("."); {
free (dir);
dir = xstrdup (".");
}
_cpp_simplify_pathname (dir); _cpp_simplify_pathname (dir);
if (stat (dir, &st)) if (stat (dir, &st))
{ {
/* Dirs that don't exist are silently ignored. */ /* Dirs that don't exist are silently ignored. */
...@@ -221,12 +225,14 @@ append_include_chain (pfile, dir, path, cxx_aware) ...@@ -221,12 +225,14 @@ append_include_chain (pfile, dir, path, cxx_aware)
cpp_notice_from_errno (pfile, dir); cpp_notice_from_errno (pfile, dir);
else if (CPP_OPTION (pfile, verbose)) else if (CPP_OPTION (pfile, verbose))
fprintf (stderr, _("ignoring nonexistent directory \"%s\"\n"), dir); fprintf (stderr, _("ignoring nonexistent directory \"%s\"\n"), dir);
free (dir);
return; return;
} }
if (!S_ISDIR (st.st_mode)) if (!S_ISDIR (st.st_mode))
{ {
cpp_notice (pfile, "%s: Not a directory", dir); cpp_notice (pfile, "%s: Not a directory", dir);
free (dir);
return; return;
} }
...@@ -375,7 +381,7 @@ merge_include_chains (pfile) ...@@ -375,7 +381,7 @@ merge_include_chains (pfile)
brack = remove_dup_dir (pfile, qtail); brack = remove_dup_dir (pfile, qtail);
} }
else else
quote = brack; quote = brack;
CPP_OPTION (pfile, quote_include) = quote; CPP_OPTION (pfile, quote_include) = quote;
CPP_OPTION (pfile, bracket_include) = brack; CPP_OPTION (pfile, bracket_include) = brack;
......
...@@ -2109,7 +2109,8 @@ _cpp_init_pool (pool, size, align, temp) ...@@ -2109,7 +2109,8 @@ _cpp_init_pool (pool, size, align, temp)
if (align & (align - 1)) if (align & (align - 1))
abort (); abort ();
pool->align = align; pool->align = align;
pool->cur = new_chunk (size); pool->first = new_chunk (size);
pool->cur = pool->first;
pool->locked = 0; pool->locked = 0;
pool->locks = 0; pool->locks = 0;
if (temp) if (temp)
...@@ -2136,7 +2137,7 @@ void ...@@ -2136,7 +2137,7 @@ void
_cpp_free_pool (pool) _cpp_free_pool (pool)
cpp_pool *pool; cpp_pool *pool;
{ {
cpp_chunk *chunk = pool->cur, *next; cpp_chunk *chunk = pool->first, *next;
do do
{ {
...@@ -2144,7 +2145,7 @@ _cpp_free_pool (pool) ...@@ -2144,7 +2145,7 @@ _cpp_free_pool (pool)
free (chunk->base); free (chunk->base);
chunk = next; chunk = next;
} }
while (chunk && chunk != pool->cur); while (chunk && chunk != pool->first);
} }
/* Reserve LEN bytes from a memory pool. */ /* Reserve LEN bytes from a memory pool. */
......
...@@ -901,7 +901,8 @@ cpp_register_pragma (pfile, space, name, handler) ...@@ -901,7 +901,8 @@ cpp_register_pragma (pfile, space, name, handler)
} }
found: found:
new = xnew (struct pragma_entry); new = (struct pragma_entry *)
_cpp_pool_alloc (&pfile->macro_pool, sizeof (struct pragma_entry));
new->name = name; new->name = name;
new->len = strlen (name); new->len = strlen (name);
new->isnspace = 0; new->isnspace = 0;
...@@ -929,7 +930,8 @@ cpp_register_pragma_space (pfile, space) ...@@ -929,7 +930,8 @@ cpp_register_pragma_space (pfile, space)
p = p->next; p = p->next;
} }
new = xnew (struct pragma_entry); new = (struct pragma_entry *)
_cpp_pool_alloc (&pfile->macro_pool, sizeof (struct pragma_entry));
new->name = space; new->name = space;
new->len = len; new->len = len;
new->isnspace = 1; new->isnspace = 1;
......
...@@ -94,6 +94,17 @@ ht_create (order) ...@@ -94,6 +94,17 @@ ht_create (order)
return table; return table;
} }
/* Frees all memory associated with a hash table. */
void
ht_destroy (table)
hash_table *table;
{
obstack_free (&table->stack, NULL);
free (table->entries);
free (table);
}
/* Returns the hash entry for the a STR of length LEN. If that string /* Returns the hash entry for the a STR of length LEN. If that string
already exists in the table, returns the existing entry, and, if already exists in the table, returns the existing entry, and, if
INSERT is CPP_ALLOCED, frees the last obstack object. If the INSERT is CPP_ALLOCED, frees the last obstack object. If the
......
...@@ -64,8 +64,13 @@ struct ht ...@@ -64,8 +64,13 @@ struct ht
}; };
extern void gcc_obstack_init PARAMS ((struct obstack *)); extern void gcc_obstack_init PARAMS ((struct obstack *));
/* Initialise the hashtable with 2 ^ order entries. */ /* Initialise the hashtable with 2 ^ order entries. */
extern hash_table *ht_create PARAMS ((unsigned int order)); extern hash_table *ht_create PARAMS ((unsigned int order));
/* Frees all memory associated with a hash table. */
extern void ht_destroy PARAMS ((hash_table *));
extern hashnode ht_lookup PARAMS ((hash_table *, const unsigned char *, extern hashnode ht_lookup PARAMS ((hash_table *, const unsigned char *,
unsigned int, enum ht_lookup_option)); unsigned int, enum ht_lookup_option));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment