Bugs item #1894726, was opened at 2008-02-16 00:44
Message generated for change (Comment added) made by lebert
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=111005&aid=1894726&group_id=11005

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Program
Group: None
Status: Closed
Resolution: Fixed
Priority: 5
Private: No
Submitted By: Bert Wesarg (lebert)
Assigned to: Nobody/Anonymous (nobody)
Summary: fix memoy leak in PromoteToGlobal()

Initial Comment:
InstallSymbol() allocates a new Symbol and put this to the GlobalSymList the 
Symbol passed to PromoteToGlobal() is lost.

This patch adds the Symbol directly to the GlobalSymList, without calling 
InstallSymbol().

The case in which the Symbol is already in the LocalSymbolList is not changed, 
because I don't know if this can a cause SIGSEGV but it should also be 
corrected (ie freeing sym).

----------------------------------------------------------------------

>Comment By: Bert Wesarg (lebert)
Date: 2008-03-26 10:21

Message:
Logged In: YES 
user_id=122956
Originator: YES

This is the optimistic version.

You assume that PromoteToGlobal() has the only reference to the symbol
passed. This is currently correct. If you assume this, than you can simply
free the symbol and return the symbol from the GlobalSymList, in case the
symbol was found there, which should not happen currently. The next
assumption you made is, that a LOCAL_SYM can never be in the GlobalSymList.
This is currently true, hopefully.

I have tried to address both assumptions in the commit and put in
fprintf's. Also, as I stated in the comment, I think these are parser
errors, which should error out the parsing process.

----------------------------------------------------------------------

Comment By: Tony Balinski (ajbj)
Date: 2008-03-26 01:55

Message:
Logged In: YES 
user_id=618141
Originator: NO

After consideration I don't agree with the committed solution.

All that needs to be done is: if the symbol being promoted is on the local
list, take it off that one, change its type to GLOBAL_SYM, then add it to
the global list if it isn't already there, or delete it if it is.

See http://www.nedit.org/pipermail/develop/2008-March/014355.html and
http://www.nedit.org/pipermail/develop/2008-March/014365.html (my analysis
was correct and Bert's response true).

The solution I propose is:

/*
** Promote a symbol from local to global, removing it from the local
symbol
** list.
**
** The parser assumes that all non-global symbols are for local variables
** (unless already known) until it sees a following parenthesis
(supposedly
** starting an argument list). When this happens, PromoteToGlobal() is
called
** so that the symbol is placed on the global symbol list, since this is
where
** all function symbols should be held. Since, when this occurs, there is
as
** yet no function defined, we say the symbol is still that of a variable
(now
** global). This will be overwritten correctly when a definition of a
function
** with that symbol is read.
*/
Symbol *PromoteToGlobal(Symbol *sym)
{
    Symbol *s, *global_sym;
    static DataValue noValue = {NO_TAG, {0}};

    if (sym->type != LOCAL_SYM)
        return sym;

    /* Remove sym from the local symbol list */
    if (sym == LocalSymList)
        LocalSymList = sym->next;
    else {
        for (s = LocalSymList; s != NULL; s = s->next) {
            if (s->next == sym) {
                s->next = sym->next;
                break;
            }
        }
    }
    sym->next = NULL;

    global_sym = LookupSymbol(sym->name);
    if (global_sym != NULL) {
        /* get rid of sym's instance - the name is already there */
        freeSymbolTable(sym);
    }
    else {
        /* put sym on the global list */
        sym->next = GlobalSymList;
        sym->type = GLOBAL_SYM;
        GlobalSymList = global_sym = sym;
    }
    return global_sym;
}


----------------------------------------------------------------------

Comment By: Bert Wesarg (lebert)
Date: 2008-03-09 17:40

Message:
Logged In: YES 
user_id=122956
Originator: YES

committed with plenty of new comments ;-)

----------------------------------------------------------------------

Comment By: Bert Wesarg (lebert)
Date: 2008-03-01 02:07

Message:
Logged In: YES 
user_id=122956
Originator: YES

I will commit this fix by the next week. There is only the problem with
the extra LookupSymbol() call. I suspect that this would be a greater
error, if this call ever succeeded, because that would mean that a
LOCAL_SYM was not in the LocalSymList, or there was previously a non
LOCAL_SYM in the GlobalSymList. I would like to add a fprintf instead of
the return, and see if this case is ever triggered (see the new patch).


File Added: fix-mem-leak-in-PromoteToGlobal.patch

----------------------------------------------------------------------

Comment By: Nobody/Anonymous (nobody)
Date: 2008-02-16 23:10

Message:
Logged In: NO 

should be updated to CVS immediately

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=111005&aid=1894726&group_id=11005
-- 
NEdit Develop mailing list - [email protected]
http://www.nedit.org/mailman/listinfo/develop

Reply via email to