]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/PyModule: do not lock in get_name()
authorMax Kellermann <max.kellermann@ionos.com>
Fri, 11 Oct 2024 10:32:11 +0000 (12:32 +0200)
committerMax Kellermann <max.kellermann@ionos.com>
Mon, 9 Dec 2024 07:18:48 +0000 (08:18 +0100)
The way get_name() used the lock is completely wrong: in the protected
code block, it do not access anything that needs to be protected.  All
it effectively does is return the `this` pointer with an offset to the
`module_name` field; but it does not actually access the field.  The
actual access is done by the caller, after the mutex has been unlocked
already.

But anyway, `module_name` does not need any protection.  It is `const`
and thus cannot be modified by other threads.  So instead of fixing
the return value (removing the `&`), let's just remove the lock.

Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
src/mgr/PyModule.h

index 177447c2cb323cec7d04599dc22c3cd4b706cda9..3dd39a778656ca197ab5ddd47c78e7b0b6faa7c3 100644 (file)
@@ -161,7 +161,7 @@ public:
   }
 
   const std::string &get_name() const {
-    std::lock_guard l(lock) ; return module_name;
+    return module_name;
   }
   const std::string &get_error_string() const {
     std::lock_guard l(lock) ; return error_string;