[vlc-commits] commit: vlc_rand_bytes: minor thread-safety fix ( Rémi Denis-Courmont )
git at videolan.org
git at videolan.org
Sat Mar 6 11:30:21 CET 2010
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Mar 6 11:46:03 2010 +0200| [26e7928801f206ae1aade88c161a6c3106a75f3f] | committer: Rémi Denis-Courmont
vlc_rand_bytes: minor thread-safety fix
We need the lock to read okey and ikey
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=26e7928801f206ae1aade88c161a6c3106a75f3f
---
src/misc/rand.c | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/src/misc/rand.c b/src/misc/rand.c
index 081ece3..8932e40 100644
--- a/src/misc/rand.c
+++ b/src/misc/rand.c
@@ -92,19 +92,21 @@ void vlc_rand_bytes (void *buf, size_t len)
uint64_t val;
struct md5_s mdi, mdo;
+ InitMD5 (&mdi);
+ InitMD5 (&mdo);
+
pthread_mutex_lock (&lock);
if (counter == 0)
vlc_rand_init ();
val = counter++;
- pthread_mutex_unlock (&lock);
- InitMD5 (&mdi);
AddMD5 (&mdi, ikey, sizeof (ikey));
+ AddMD5 (&mdo, okey, sizeof (okey));
+ pthread_mutex_unlock (&lock);
+
AddMD5 (&mdi, &stamp, sizeof (stamp));
AddMD5 (&mdi, &val, sizeof (val));
EndMD5 (&mdi);
- InitMD5 (&mdo);
- AddMD5 (&mdo, okey, sizeof (okey));
AddMD5 (&mdo, mdi.p_digest, sizeof (mdi.p_digest));
EndMD5 (&mdo);
More information about the vlc-commits
mailing list