Bugs in HTAnchor_delete

There seem to be two bugs in HTAnchor_delete in HTAnchor.c. I think that one of the bugs has been already mentioned by someone on this mailing list.

On lines 503 - 506,

            while ((child=(HTChildAnchor *) HTList_removeLastObject(kids)))
            delete_links((HTAnchor *) child);
            HT_FREE(child->tag);
            HT_FREE(child);

I believe this is meant to be

            while ((child=(HTChildAnchor *) HTList_removeLastObject(kids))) {
            delete_links((HTAnchor *) child);
            HT_FREE(child->tag);
            HT_FREE(child);
            }

The other is a wrong placement of a bracket.

    if (!HTList_isEmpty(me->sources)) {    /* There are still incoming links */

    /*
    ** Delete all outgoing links from children, if any
    */
    if (me->children) {
        int cnt = 0;
        for (; cnt<CHILD_HASH_SIZE; cnt++) {
        HTList * kids = me->children[cnt];
        if (kids) {
            HTChildAnchor * child;
            while ((child = (HTChildAnchor *) HTList_nextObject(kids)))
            delete_links((HTAnchor *) child);
            return NO;  /* Parent not deleted */
        }
        }
    }

    /*
    ** No more incoming links : kill everything
    ** First, recursively delete children
    */
    if (me->children) {
        int cnt = 0;
        for (; cnt<CHILD_HASH_SIZE; cnt++) {
        HTList * kids = me->children[cnt];
        if (kids) {
            HTChildAnchor * child;
            while ((child=(HTChildAnchor *) HTList_removeLastObject(kids)))
            delete_links((HTAnchor *) child);
            HT_FREE(child->tag);
            HT_FREE(child);
        }
        }
    }
    } <----

The comments indicate that the anchor is allowed to be erased only when there are no more incoming sources for the anchor. However, "if (!HTList_isEmpty(me->sources)) {" encloses statements that belong to the no-more-incoming-links case. The bracket at the line 510 should probably be moved somewhere around the line 492.

Received on Thursday, 4 October 2001 07:09:12 UTC