comparison src/dmres.c @ 2262:f92d4f056587

The return value of dmResourceRef() and dmResourceUnref() had a possibility of being off by one due to a potential race condition. Fixed.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 17 Jun 2019 00:57:02 +0300
parents e286454d305f
children 36edd316184a
comparison
equal deleted inserted replaced
2261:e286454d305f 2262:f92d4f056587
1012 } 1012 }
1013 1013
1014 1014
1015 int dmResourceRef(DMResource *node) 1015 int dmResourceRef(DMResource *node)
1016 { 1016 {
1017 int res;
1018
1017 dmLockLibMutex(node->lib); 1019 dmLockLibMutex(node->lib);
1018 node->atime = time(NULL); 1020 node->atime = time(NULL);
1019 node->refcount++; 1021 res = ++node->refcount;
1020 dmUnlockLibMutex(node->lib); 1022 dmUnlockLibMutex(node->lib);
1021 1023
1022 return node->refcount; 1024 return res;
1023 } 1025 }
1024 1026
1025 1027
1026 int dmResourceUnref(DMResource *node) 1028 int dmResourceUnref(DMResource *node)
1027 { 1029 {
1030 int res;
1031
1028 dmLockLibMutex(node->lib); 1032 dmLockLibMutex(node->lib);
1029 node->refcount--; 1033 res = --node->refcount;
1030 dmUnlockLibMutex(node->lib); 1034 dmUnlockLibMutex(node->lib);
1031 1035
1032 return node->refcount; 1036 return res;
1033 } 1037 }
1034 1038
1035 1039
1036 #ifdef DM_USE_STDIO 1040 #ifdef DM_USE_STDIO
1037 static int dmResourcesLoadDirectory(DMResourceLib *lib, const char *path) 1041 static int dmResourcesLoadDirectory(DMResourceLib *lib, const char *path)