Change variable scopes

cppcheck correctly notes that a lot of our variables can be declared at
more specific scopes, and in every case, it seems to be correct.

Tested: Redfish service validator passes.  Unit test coverage on others.

Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Ia4414410d0e8f74a3bd40fdc0e0232450d1a6416
diff --git a/include/dbus_monitor.hpp b/include/dbus_monitor.hpp
index 5f409d7..0838f0a 100644
--- a/include/dbus_monitor.hpp
+++ b/include/dbus_monitor.hpp
@@ -167,9 +167,7 @@
         // PropertiesChanged
         thisSession.matches.reserve(thisSession.matches.size() +
                                     paths->size() * (1U + interfaceCount));
-        std::string objectManagerMatchString;
-        std::string propertiesMatchString;
-        std::string objectManagerInterfacesMatchString;
+
         // These regexes derived on the rules here:
         // https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names
         std::regex validPath("^/([A-Za-z0-9_]+/?)*$");
@@ -192,7 +190,7 @@
                 conn.close();
                 return;
             }
-            propertiesMatchString =
+            std::string propertiesMatchString =
                 ("type='signal',"
                  "interface='org.freedesktop.DBus.Properties',"
                  "path_namespace='" +
@@ -234,7 +232,7 @@
                             onPropertyUpdate, &conn));
                 }
             }
-            objectManagerMatchString =
+            std::string objectManagerMatchString =
                 ("type='signal',"
                  "interface='org.freedesktop.DBus.ObjectManager',"
                  "path_namespace='" +
diff --git a/include/http_utility.hpp b/include/http_utility.hpp
index cd1be3e..e1a8e2a 100644
--- a/include/http_utility.hpp
+++ b/include/http_utility.hpp
@@ -44,11 +44,10 @@
 inline ContentType getPreferedContentType(std::string_view header,
                                           std::span<ContentType> preferedOrder)
 {
-    size_t index = 0;
     size_t lastIndex = 0;
     while (lastIndex < header.size() + 1)
     {
-        index = header.find(',', lastIndex);
+        size_t index = header.find(',', lastIndex);
         if (index == std::string_view::npos)
         {
             index = header.size();
diff --git a/include/ibm/locks.hpp b/include/ibm/locks.hpp
index e713f97..e3abb46 100644
--- a/include/ibm/locks.hpp
+++ b/include/ibm/locks.hpp
@@ -431,12 +431,9 @@
 
 inline Rc Lock::isConflictWithTable(const LockRequests& refLockRequestStructure)
 {
-
-    uint32_t thisTransactionId = 0;
-
     if (lockTable.empty())
     {
-        thisTransactionId = generateTransactionId();
+        uint32_t thisTransactionId = generateTransactionId();
         BMCWEB_LOG_DEBUG << thisTransactionId;
         // Lock table is empty, so we are safe to add the lockrecords
         // as there will be no conflict
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index 95503d7..0e3e070 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -432,7 +432,6 @@
         {
             for (const auto& connection : object.second)
             {
-                std::string& objectManagerPath = connections[connection.first];
                 for (const auto& interface : connection.second)
                 {
                     BMCWEB_LOG_DEBUG << connection.first << " has interface "
@@ -441,7 +440,7 @@
                     {
                         BMCWEB_LOG_DEBUG << "found object manager path "
                                          << object.first;
-                        objectManagerPath = object.first;
+                        connections[connection.first] = object.first;
                     }
                 }
             }