GNOME Bugzilla – Bug 747437
xmlMemUsed is not thread-safe
Last modified: 2015-04-13 08:48:42 UTC
All modifying access to debugMemSize is protected by xmlMemMutex, but the reading access of xmlMemUsed is not. This means that in a multi-threaded environment, that read can return pretty much arbitrary values. I'm investigating this in connection with the node.js bindings libxmljs, where xmlMemUsed is used to keep the garbage collector informed of current memory usage. See https://github.com/polotek/libxmljs/issues/296 for details.
Ah, right, to be honest I have only used that framework for memory debugging, the problem is that the memory allocator is global to the process and if another library end up using libxml2 in the same process then all bets are off. Seems the fix for your use case is trivial, just also protect the read only access with xmlMemMutex too. Would you mind submitting a patch ? Daniel
Created attachment 301438 [details] [review] Add mutex locks Adding mutex locks to xmlMemUsed and xmlMemBlocks.
Okidoc, I just add to move the declaration of the return value at the top of the block: https://git.gnome.org/browse/libxml2/commit/?id=8985cde70901c62d3f0f04da225e73b7344a52d7 thanks ! Daniel