forked from lda/telodendria
Lock database in DbExists() to prevent race conditions.
This commit is contained in:
parent
c5bce0b14f
commit
b8ce4c9239
1 changed files with 14 additions and 1 deletions
15
src/Db.c
15
src/Db.c
|
@ -736,10 +736,23 @@ DbExists(Db * db, size_t nArgs,...)
|
||||||
args = ArrayFromVarArgs(nArgs, ap);
|
args = ArrayFromVarArgs(nArgs, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
file = DbFileName(db, args);
|
if (!args)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Though it's not explicitly required, we lock the
|
||||||
|
* database before checking that an object exists to
|
||||||
|
* prevent any potential race conditions.
|
||||||
|
*/
|
||||||
|
pthread_mutex_lock(&db->lock);
|
||||||
|
|
||||||
|
file = DbFileName(db, args);
|
||||||
ret = UtilLastModified(file);
|
ret = UtilLastModified(file);
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&db->lock);
|
||||||
|
|
||||||
Free(file);
|
Free(file);
|
||||||
ArrayFree(args);
|
ArrayFree(args);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue