After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 747437 - xmlMemUsed is not thread-safe
xmlMemUsed is not thread-safe
Status: RESOLVED FIXED
Product: libxml2
Classification: Platform
Component: general
git master
Other Linux
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2015-04-07 08:36 UTC by Martin von Gagern
Modified: 2015-04-13 08:48 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add mutex locks (575 bytes, patch)
2015-04-13 07:18 UTC, Martin von Gagern
none Details | Review

Description Martin von Gagern 2015-04-07 08:36:33 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.
Comment 1 Daniel Veillard 2015-04-08 08:55:41 UTC
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
Comment 2 Martin von Gagern 2015-04-13 07:18:22 UTC
Created attachment 301438 [details] [review]
Add mutex locks

Adding mutex locks to xmlMemUsed and xmlMemBlocks.
Comment 3 Daniel Veillard 2015-04-13 08:48:42 UTC
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