This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/40877] memory leaks with gfc_charlen?
- From: "janus at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 5 Aug 2009 11:27:16 -0000
- Subject: [Bug fortran/40877] memory leaks with gfc_charlen?
- References: <bug-40877-16146@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #2 from janus at gcc dot gnu dot org 2009-08-05 11:27 -------
(In reply to comment #1)
> * trans-decl.c (create_function_arglist)
>
> This is OK - the new cl is threaded into the list.
Actually I think that this is not done properly. The code in question is:
gfc_charlen *cl, *cl2;
cl = f->sym->ts.cl;
f->sym->ts.cl = gfc_get_charlen();
f->sym->ts.cl->length = cl->length;
f->sym->ts.cl->backend_decl = cl->backend_decl;
f->sym->ts.cl->length_from_typespec = cl->length_from_typespec;
f->sym->ts.cl->resolved = cl->resolved;
cl2 = f->sym->ts.cl->next;
f->sym->ts.cl->next = cl;
cl->next = cl2;
First problem: cl2 is always NULL, since f->sym->ts.cl gets assigned a fresh
gfc_charlen.
Second problem: The new charlen is inserted in front of the old one, and not
behind it.
Let's say before this code is executed we have a linked list of charlen
structures like this:
something -> cl -> ...
After the code is executed this will look like:
something---
|
new_cl -> cl -> NULL
where 'something' still points to 'cl', so 'new_cl' is not reachable from
within the linked list (and also cl->next is lost).
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40877