From 1503af41e1e70c6957982d0b48c4f9ff40feee2d Mon Sep 17 00:00:00 2001
From: Tristan Matthews <tristan.matthews@savoirfairelinux.com>
Date: Thu, 14 Mar 2013 17:02:43 -0400
Subject: [PATCH] * #21631: fileutils: don't return pointer to function-local
 object

The string in question would be destroyed before we used the pointer.
---
 daemon/src/fileutils.cpp | 6 +++---
 daemon/src/fileutils.h   | 4 +++-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/daemon/src/fileutils.cpp b/daemon/src/fileutils.cpp
index 4f9bfa2ea8..7a01138827 100644
--- a/daemon/src/fileutils.cpp
+++ b/daemon/src/fileutils.cpp
@@ -84,10 +84,10 @@ const char *get_program_dir()
 }
 
 // FIXME: This should use our real DATADIR
-const char *get_data_dir()
+std::string
+get_data_dir()
 {
-    std::string path = std::string(get_program_dir()) + "/../../share/sflphone/ringtones/";
-    return path.c_str();
+    return std::string(get_program_dir()) + "/../../share/sflphone/ringtones/";
 }
 
 namespace {
diff --git a/daemon/src/fileutils.h b/daemon/src/fileutils.h
index 6f5bda13fb..6a569e2bdc 100644
--- a/daemon/src/fileutils.h
+++ b/daemon/src/fileutils.h
@@ -31,6 +31,8 @@
 #ifndef FILEUTILS_H_
 #define FILEUTILS_H_
 
+#include <string>
+
 #define PROTECTED_GETENV(str) ({char *envvar_ = getenv((str)); \
                                                    envvar_ ? envvar_ : "";})
 
@@ -49,7 +51,7 @@ namespace fileutils {
     bool check_dir(const char *path);
     void set_program_dir(char *program_path);
     const char *get_program_dir();
-    const char *get_data_dir();
+    std::string get_data_dir();
     bool isDirectoryWritable(const std::string &directory);
     struct FileHandle {
         int fd;
-- 
GitLab