[Orxonox-commit 6450] r11106 - code/trunk/src/libraries/core/input

muemart at orxonox.net muemart at orxonox.net
Wed Feb 3 13:02:33 CET 2016


Author: muemart
Date: 2016-02-03 13:02:33 +0100 (Wed, 03 Feb 2016)
New Revision: 11106

Modified:
   code/trunk/src/libraries/core/input/KeyBinder.cc
   code/trunk/src/libraries/core/input/KeyBinder.h
Log:
Fix a memory leak. Also fix some potentially invalid references to vector elements after the vector resized.

Modified: code/trunk/src/libraries/core/input/KeyBinder.cc
===================================================================
--- code/trunk/src/libraries/core/input/KeyBinder.cc	2016-02-01 16:27:49 UTC (rev 11105)
+++ code/trunk/src/libraries/core/input/KeyBinder.cc	2016-02-03 12:02:33 UTC (rev 11106)
@@ -323,7 +323,7 @@
     @brief
         Return the first key name for a specific command
     */
-    const std::string& KeyBinder::getBinding(const std::string& commandName)
+    std::string KeyBinder::getBinding(const std::string& commandName)
     {
         if (this->allCommands_.find(commandName) != this->allCommands_.end())
         {
@@ -342,7 +342,7 @@
     @param index
         The index at which the key name is returned for.
     */
-    const std::string& KeyBinder::getBinding(const std::string& commandName, unsigned int index)
+    std::string KeyBinder::getBinding(const std::string& commandName, unsigned int index)
     {
         if (this->allCommands_.find(commandName) != this->allCommands_.end())
         {
@@ -360,9 +360,9 @@
     @brief
         Return the first key name for a specific command in a human readable form
     */
-    const std::string& KeyBinder::getBindingReadable(const std::string& commandName)
+    std::string KeyBinder::getBindingReadable(const std::string& commandName)
     {
-        const std::string& binding = this->getBinding(commandName);
+        std::string binding = this->getBinding(commandName);
 
         SubString substring = SubString(binding, ".");
         std::string name;
@@ -393,7 +393,8 @@
         else
             return binding;
 
-        return *(new std::string(stream.str()));
+        binding = stream.str();
+        return binding;
     }
 
     /**

Modified: code/trunk/src/libraries/core/input/KeyBinder.h
===================================================================
--- code/trunk/src/libraries/core/input/KeyBinder.h	2016-02-01 16:27:49 UTC (rev 11105)
+++ code/trunk/src/libraries/core/input/KeyBinder.h	2016-02-03 12:02:33 UTC (rev 11106)
@@ -65,9 +65,9 @@
 
         void clearBindings();
         bool setBinding(const std::string& binding, const std::string& name, bool bTemporary = false);
-        const std::string& getBinding(const std::string& commandName); //tolua_export
-        const std::string& getBinding(const std::string& commandName, unsigned int index); //tolua_export
-        const std::string& getBindingReadable(const std::string& commandName); //tolua_export
+        std::string getBinding(const std::string& commandName); //tolua_export
+        std::string getBinding(const std::string& commandName, unsigned int index); //tolua_export
+        std::string getBindingReadable(const std::string& commandName); //tolua_export
         unsigned int getNumberOfBindings(const std::string& commandName); //tolua_export
 
         const std::string& getBindingsFilename()




More information about the Orxonox-commit mailing list