Use non-recursive mutex in dict.c

The mutex is never locked recursively.
This commit is contained in:
Nick Wellnhofer 2022-03-06 14:58:04 +01:00
parent 40483d0ce2
commit 3241c47c1f

24
dict.c
View File

@ -127,7 +127,7 @@ struct _xmlDict {
* A mutex for modifying the reference counter for shared
* dictionaries.
*/
static xmlRMutexPtr xmlDictMutex = NULL;
static xmlMutexPtr xmlDictMutex = NULL;
/*
* Whether the dictionary mutex was initialized.
@ -174,9 +174,9 @@ int __xmlInitializeDict(void) {
if (xmlDictInitialized)
return(1);
if ((xmlDictMutex = xmlNewRMutex()) == NULL)
if ((xmlDictMutex = xmlNewMutex()) == NULL)
return(0);
xmlRMutexLock(xmlDictMutex);
xmlMutexLock(xmlDictMutex);
#ifdef DICT_RANDOMIZATION
#ifdef HAVE_RAND_R
@ -187,7 +187,7 @@ int __xmlInitializeDict(void) {
#endif
#endif
xmlDictInitialized = 1;
xmlRMutexUnlock(xmlDictMutex);
xmlMutexUnlock(xmlDictMutex);
return(1);
}
@ -198,13 +198,13 @@ int __xmlRandom(void) {
if (xmlDictInitialized == 0)
__xmlInitializeDict();
xmlRMutexLock(xmlDictMutex);
xmlMutexLock(xmlDictMutex);
#ifdef HAVE_RAND_R
ret = rand_r(& rand_seed);
#else
ret = rand();
#endif
xmlRMutexUnlock(xmlDictMutex);
xmlMutexUnlock(xmlDictMutex);
return(ret);
}
#endif
@ -225,7 +225,7 @@ xmlDictCleanup(void) {
if (!xmlDictInitialized)
return;
xmlFreeRMutex(xmlDictMutex);
xmlFreeMutex(xmlDictMutex);
xmlDictInitialized = 0;
}
@ -650,9 +650,9 @@ xmlDictReference(xmlDictPtr dict) {
return(-1);
if (dict == NULL) return -1;
xmlRMutexLock(xmlDictMutex);
xmlMutexLock(xmlDictMutex);
dict->ref_counter++;
xmlRMutexUnlock(xmlDictMutex);
xmlMutexUnlock(xmlDictMutex);
return(0);
}
@ -814,14 +814,14 @@ xmlDictFree(xmlDictPtr dict) {
return;
/* decrement the counter, it may be shared by a parser and docs */
xmlRMutexLock(xmlDictMutex);
xmlMutexLock(xmlDictMutex);
dict->ref_counter--;
if (dict->ref_counter > 0) {
xmlRMutexUnlock(xmlDictMutex);
xmlMutexUnlock(xmlDictMutex);
return;
}
xmlRMutexUnlock(xmlDictMutex);
xmlMutexUnlock(xmlDictMutex);
if (dict->subdict != NULL) {
xmlDictFree(dict->subdict);