ICU-7948 Fix leak in usprep_getProfile when 2 threads race to insert profile data into hash
X-SVN-Rev: 28627
This commit is contained in:
parent
290cadf0b8
commit
467cf876fc
@ -374,19 +374,27 @@ usprep_getProfile(const char* path,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* initialize the key members */
|
||||
key->name = keyName.orphan();
|
||||
uprv_strcpy(key->name, name);
|
||||
if(path != NULL){
|
||||
key->path = keyPath.orphan();
|
||||
uprv_strcpy(key->path, path);
|
||||
}
|
||||
|
||||
profile = newProfile.orphan();
|
||||
umtx_lock(&usprepMutex);
|
||||
/* add the data object to the cache */
|
||||
profile->refCount = 1;
|
||||
uhash_put(SHARED_DATA_HASHTABLE, key.orphan(), profile, status);
|
||||
// If another thread already inserted the same key/value, refcount and cleanup our thread data
|
||||
profile = (UStringPrepProfile*) (uhash_get(SHARED_DATA_HASHTABLE,&stackKey));
|
||||
if(profile != NULL) {
|
||||
profile->refCount++;
|
||||
usprep_unload(newProfile.getAlias());
|
||||
}
|
||||
else {
|
||||
/* initialize the key members */
|
||||
key->name = keyName.orphan();
|
||||
uprv_strcpy(key->name, name);
|
||||
if(path != NULL){
|
||||
key->path = keyPath.orphan();
|
||||
uprv_strcpy(key->path, path);
|
||||
}
|
||||
profile = newProfile.orphan();
|
||||
|
||||
/* add the data object to the cache */
|
||||
profile->refCount = 1;
|
||||
uhash_put(SHARED_DATA_HASHTABLE, key.orphan(), profile, status);
|
||||
}
|
||||
umtx_unlock(&usprepMutex);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user