trylock_stream bug (exposed as gpgrt_ftrylockfile)
Open, HighPublic

Assigned To
None
Authored By
• gniibe
Wed, Oct 14, 4:49 AM

Description

trylock_stream has a bug, it seems that it never works correctly.

Event Timeline

• gniibe created this task.

Internally, _gpgrt_lock_trylock returns an error code on error, 0 when success.
It seems that trylock_stream (and thus gpgrt_ftrylockfile) should return -1 on error, 0 when success.

Here is a patch:

diff --git a/src/estream.c b/src/estream.c
index ba345ff..301a078 100644
--- a/src/estream.c
+++ b/src/estream.c
@@ -476,7 +476,7 @@ trylock_stream (estream_t _GPGRT__RESTRICT stream)
   if (!stream->intern->samethread)
     {
       dbg_lock_1 ("enter trylock_stream for %p\n", stream);
-      rc = _gpgrt_lock_trylock (&stream->intern->lock)? 0 : -1;
+      rc = _gpgrt_lock_trylock (&stream->intern->lock)? -1 : 0;
       dbg_lock_2 ("leave trylock_stream for %p: rc=%d\n", stream, rc);
     }
   else