multipath-tools: release lock on handler failure
PATCH 1/1 multipath-tools: release lock on handler failure
Inside parse_cmd() the pthread_cleanup_pop() rely on '!r' as the indicator of locked or not, while this will be overwritten if the handler return failed, and the unlock will be missing.
This will lead into the situation that all the following operation will trying to hold a lock which will never be released.
This patch using a separate flag to record the status of locking to make sure the unlock and lock are in pairs.
--- multipathd/cli.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
multipathd/cli.c +3 -1
@@ -481,6 +481,7 @@ parse_cmd (char * cmd, char ** reply, int * len, void * data, int timeout ) tmo.tv_sec =0 ; }if (h->locked) { +int locked =0 ;struct vectors * vecs = (struct vectors *)data;pthread_cleanup_push (cleanup_lock, &vecs->lock);
@@ -491,10 +492,11 @@ parse_cmd (char * cmd, char ** reply, int * len, void * data, int timeout ) r =0 ; }if (r ==0 ) { + locked =1 ;pthread_testcancel (); r = h->fn (cmdvec, reply, len, data); } -pthread_cleanup_pop (!r); +pthread_cleanup_pop (locked); }else r = h->fn (cmdvec, reply, len, data);free_keys (cmdvec);
Signature · 1 line
2.5.0
Dear maintainer, is this patch looks fine to you?
Regards,
Michael Wang
Quoted 42 lines · Michael Wang
Inside
parse_cmd()thepthread_cleanup_pop()rely on '!r' as the indicator of locked or not, while this will be overwritten if the handler return failed, and the unlock will be missing.This will lead into the situation that all the following operation will trying to hold a lock which will never be released.
This patch using a separate flag to record the status of locking to make sure the unlock and lock are in pairs.
Signed-off-by Michael Wang <[email protected]>--- multipathd/cli.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)multipathd/cli.c +3
-1@@ -481,6 +481,7 @@ parse_cmd (char * cmd, char ** reply, int * len, void * data, int timeout ) tmo.tv_sec =0 ; }if (h->locked) { +int locked =0 ;struct vectors * vecs = (struct vectors *)data;pthread_cleanup_push (cleanup_lock, &vecs->lock);@@ -491,10 +492,11 @@ parse_cmd (char * cmd, char ** reply, int * len, void * data, int timeout ) r =0 ; }if (r ==0 ) { + locked =1 ;pthread_testcancel (); r = h->fn (cmdvec, reply, len, data); } -pthread_cleanup_pop (!r); +pthread_cleanup_pop (locked); }else r = h->fn (cmdvec, reply, len, data);free_keys (cmdvec);
Merged.
Thanks.
Quoted 51 lines · Michael Wang
Dear maintainer, is this patch looks fine to you?
Regards,
Michael Wangmultipathd/cli.c parse_cmd (char * cmd, char ** reply, int * len,
Quoted 21 lines · Michael Wang
Inside
parse_cmd()thepthread_cleanup_pop()rely on '!r' as the indicator of locked or not, while this will be overwritten if the handler return failed, and the unlock will be missing.This will lead into the situation that all the following operation will trying to hold a lock which will never be released.
This patch using a separate flag to record the status of locking to make sure the unlock and lock are in pairs.
Signed-off-by Michael Wang <[email protected]>--- multipathd/cli.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)multipathd/cli.c +0
-0@@ -481,6 +481,7 @@ parse_cmd (char * cmd, char ** reply, int * len,void * data, int timeout )
multipathd/cli.c parse_cmd (char * cmd, char ** reply, int * len,
Quoted 8 lines
multipathd/cli.c +1
-0tmo.tv_sec =0 ; }if (h->locked) { +int locked =0 ;struct vectors * vecs = (struct vectors *)data;pthread_cleanup_push (cleanup_lock, &vecs->lock);@@ -491,10 +492,11 @@ parse_cmd (char * cmd, char ** reply, int * len,void * data, int timeout )
Quoted 13 lines
multipathd/cli.c +2
-1r =0 ; }if (r ==0 ) { + locked =1 ;pthread_testcancel (); r = h->fn (cmdvec, reply, len, data); } -pthread_cleanup_pop (!r); +pthread_cleanup_pop (locked); }else r = h->fn (cmdvec, reply, len, data);free_keys (cmdvec);