diff --git a/include/libcamera/bound_method.h b/include/libcamera/bound_method.h
index f216e3b56826..de17fdee3612 100644
--- a/include/libcamera/bound_method.h
+++ b/include/libcamera/bound_method.h
@@ -163,7 +163,8 @@ public:
 
 	R invoke(Args... args) override
 	{
-		return (static_cast<T *>(this->obj_)->*func_)(args...);
+		T *obj = static_cast<T *>(this->obj_);
+		return (obj->*func_)(args...);
 	}
 
 private:
@@ -195,7 +196,8 @@ public:
 
 	void invoke(Args... args) override
 	{
-		(static_cast<T *>(this->obj_)->*func_)(args...);
+		T *obj = static_cast<T *>(this->obj_);
+		(obj->*func_)(args...);
 	}
 
 private:
