From: Gary Pennington (Gary.Pennington@uk.sun.com)
Date: Thu Feb 08 2001 - 01:48:57 EST
Hi Daniel,
I was in too much of an hurry last night.
My patch introduces a memory leak. A better patch would be to always update the
hash table with the latest update (just in case something further up the call
stack expects the hash table to contain our data) and free the existing
reference.
Thus patch becomes :-
*** ../ORIG/libxml2-2.2.11/valid.c Fri Jan 5 06:39:29 2001
--- valid.c Thu Feb 8 06:44:28 2001
***************
*** 1775,1782 ****
* !!! Should we keep track of all refs ? and use xmlHashAddEntry2 ?
*/
if (xmlHashAddEntry(table, value, ret) < 0) {
! xmlFreeRef(ret);
! return(NULL);
}
return(ret);
}
--- 1775,1786 ----
* !!! Should we keep track of all refs ? and use xmlHashAddEntry2 ?
*/
if (xmlHashAddEntry(table, value, ret) < 0) {
! /*
! * Since there is no discrimination on error returns
! * from xmlHashAddEntry, I'm presuming <0 means the
! * key already exists.
! */
! xmlHashUpdateEntry(table, value, ret, (xmlHashDeallocator)
xmlFreeRef);
}
return(ret);
}
I worked out how to use the arity 2 hash functions, but they didn't solve the
problem since I couldn't work out a unique key for a reference using any of the
data in the data structures (I really needed a unique element identifier, but
since there is no such thing that won't work.). Anyway, the more I thought about
it, the more I thought that a list of entries stored at the hash for the ref key
was the right approach.
If people agree with my comments above, then I'd be happy to implement a list
based ref approach which provides a new function :-
xmlGetRefs (returns a list of refs for a key)
and which allows multiple refs to be stored under a single key. I'd be
introducing a linked list data structure for holding the refs and would also
provide some functions for walking the list, etc...
Yours,
Gary
Gary Pennington wrote:
> Hi Daniel,
>
> I think that I may have found another problem in valid.c.
>
> My fix isn't working, which makes me wonder why. Some debugging and
> investigating got me looking at xmlAddRef and it seems to be fairly wrong to
> me.
>
> Near the end of the function, there is the following section of code :-
>
> /*
> * !!! Should we keep track of all refs ? and use xmlHashAddEntry2 ?
> */
>
> if (xmlHashAddEntry(table, value, ret) < 0) {
> xmlFreeRef(ret);
> return(NULL);
> }
>
> When this code is executed any IDREF(S) which reference an ID multiple times
> (probably from different elements, but in the case of IDREFS not
> necessarily), then the add to the hash table will fail. Thus a document will
> be reported as invalid because more than one element references an ID.
>
> I took a hint from the comment and tried to fix the creation/update/access of
> refs using xmlHashAddEntry/UpdateEntry/Lookup2 - but this really broke my
> code and I was getting SIGSEGVs.
>
> So, I thought about this and decided that as long as there is an entry in the
> ref table for a ref, it doesn't matter if all refs are tracked or not. The
> only function broken by this would be the xmlGetRef function, which isn't
> actually used anywhere as far as I can tell.
>
> So my patch to get my earlier patch working is to simply add a ref and ignore
> failed adds since that means there is already a ref in the ref table.
>
> Patch is :-
>
> *** ../ORIG/libxml2-2.2.11/valid.c Fri Jan 5 06:39:29 2001
> --- valid.c Wed Feb 7 20:38:23 2001
> ***************
> *** 1774,1783 ****
> /*
> * !!! Should we keep track of all refs ? and use xmlHashAddEntry2 ?
> */
> ! if (xmlHashAddEntry(table, value, ret) < 0) {
> ! xmlFreeRef(ret);
> ! return(NULL);
> ! }
> return(ret);
> }
>
> --- 1774,1781 ----
> /*
> * !!! Should we keep track of all refs ? and use xmlHashAddEntry2 ?
> */
> !
> ! xmlHashAddEntry(table, value, ret);
> return(ret);
> }
>
> I don't really like this fix, but I couldn't get the arity 2 version of the
> hashtable logic to work, so I think this is good enough. I don't like the
> fact that it breaks xmlGetRef, but having said that I'm not sure what the
> point of xmlGetRef is anyway. Why would you want to get a single ref from a
> document, wouldn't you want all of them as a navigable list?
>
> Yours,
>
> Gary
>
> Daniel Veillard wrote:
>
> > > I've found what I think is a bug in the xmlValidateOneAttribute
> > > function. When checking for validity the routine does not detect that an
> > > error has been flagged for a duplicate ID or non existent ref without
> > > this patch. Thus invalid documents, although reported as such by the
> > > error and warning functions, are not reported as invalid by the
> > > xmlValidateDocument (etc... ) routines.
> >
> > Good catch !
> > Right the error message is not sufficient :-\
> >
> > thanks, patched, will commit !
> >
> > Daniel
> >
> > --
> > Daniel Veillard | Red Hat Network http://redhat.com/products/network/
> > veillard@redhat.com | libxml Gnome XML toolkit http://xmlsoft.org/
> > http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
> > ----
> > Message from the list xml@rpmfind.net
> > Archived at : http://xmlsoft.org/messages/
> > to unsubscribe: echo "unsubscribe xml" | mail majordomo@rpmfind.net
>
> ----
> Message from the list xml@rpmfind.net
> Archived at : http://xmlsoft.org/messages/
> to unsubscribe: echo "unsubscribe xml" | mail majordomo@rpmfind.net
---- Message from the list xml@rpmfind.net Archived at : http://xmlsoft.org/messages/ to unsubscribe: echo "unsubscribe xml" | mail majordomo@rpmfind.net
This archive was generated by hypermail 2b29 : Thu Feb 08 2001 - 02:43:48 EST