Fix invalid uses of sd_bus_error_set_const

sd_bus_error_set_const takes pointers to c-style strings as arguments
which populate its name and message. This function does not take any
ownership of the name or message, requiring the to live beyond the
lifetime of the error. Since we are destroying the error object as soon
as we leave the catch blocks, we are destroying the strings passed to
the sd_bus_error. This violates the lifetime guarantee.

Instead, use the sd_bus_error_set method which copies the strings. We
know that the callers of these callbacks free the errors by inspecting
the libsystemd code.

Tested:
    Run through unit tests which still pass

Change-Id: Ifa1533fc4c41db070f5bf2901581e9f5680cabfc
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/sdbusplus/asio/object_server.hpp b/sdbusplus/asio/object_server.hpp
index 2473e26..f535c44 100644
--- a/sdbusplus/asio/object_server.hpp
+++ b/sdbusplus/asio/object_server.hpp
@@ -395,7 +395,7 @@
 
             catch (sdbusplus::exception_t& e)
             {
-                sd_bus_error_set_const(error, e.name(), e.description());
+                sd_bus_error_set(error, e.name(), e.description());
                 return -EINVAL;
             }
             catch (...)
@@ -432,7 +432,7 @@
 
             catch (sdbusplus::exception_t& e)
             {
-                sd_bus_error_set_const(error, e.name(), e.description());
+                sd_bus_error_set(error, e.name(), e.description());
                 return -EINVAL;
             }
             catch (...)
@@ -467,7 +467,7 @@
 
             catch (sdbusplus::exception_t& e)
             {
-                sd_bus_error_set_const(error, e.name(), e.description());
+                sd_bus_error_set(error, e.name(), e.description());
                 return -EINVAL;
             }
             catch (...)
diff --git a/tools/sdbusplus/templates/method.mako.prototype.hpp.in b/tools/sdbusplus/templates/method.mako.prototype.hpp.in
index f773f3f..35c0cb9 100644
--- a/tools/sdbusplus/templates/method.mako.prototype.hpp.in
+++ b/tools/sdbusplus/templates/method.mako.prototype.hpp.in
@@ -163,13 +163,13 @@
     }
     catch(sdbusplus::internal_exception_t& e)
     {
-        sd_bus_error_set_const(error, e.name(), e.description());
+        sd_bus_error_set(error, e.name(), e.description());
         return -EINVAL;
     }
     % for e in method.errors:
     catch(sdbusplus::${error_namespace(e)}::${error_name(e)}& e)
     {
-        sd_bus_error_set_const(error, e.name(), e.description());
+        sd_bus_error_set(error, e.name(), e.description());
         return -EINVAL;
     }
     % endfor
diff --git a/tools/sdbusplus/templates/property.mako.prototype.hpp.in b/tools/sdbusplus/templates/property.mako.prototype.hpp.in
index 0322554..b170df6 100644
--- a/tools/sdbusplus/templates/property.mako.prototype.hpp.in
+++ b/tools/sdbusplus/templates/property.mako.prototype.hpp.in
@@ -54,13 +54,13 @@
     }
     catch(sdbusplus::internal_exception_t& e)
     {
-        o->_intf->sd_bus_error_set_const(error, e.name(), e.description());
+        o->_intf->sd_bus_error_set(error, e.name(), e.description());
         return -EINVAL;
     }
     % for e in property.errors:
     catch(sdbusplus::${error_namespace(e)}::${error_name(e)}& e)
     {
-        o->_intf->sd_bus_error_set_const(error, e.name(), e.description());
+        o->_intf->sd_bus_error_set(error, e.name(), e.description());
         return -EINVAL;
     }
     % endfor
@@ -120,13 +120,13 @@
     }
     catch(sdbusplus::internal_exception_t& e)
     {
-        o->_intf->sd_bus_error_set_const(error, e.name(), e.description());
+        o->_intf->sd_bus_error_set(error, e.name(), e.description());
         return -EINVAL;
     }
     % for e in property.errors:
     catch(sdbusplus::${error_namespace(e)}::${error_name(e)}& e)
     {
-        o->_intf->sd_bus_error_set_const(error, e.name(), e.description());
+        o->_intf->sd_bus_error_set(error, e.name(), e.description());
         return -EINVAL;
     }
     % endfor