From a2fbce0e7f31bdebf59bcea5282b4909c9e19837 Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Tue, 18 Aug 2015 14:44:53 +1000 Subject: Change return type and name of get_win_special_folder Rename it get_win_special_folder_path to indicate what it is returning Move documentation for the function into the header and use doxygen style comments. Fixes a couple of memory leaks in ArdourVideoToolPaths class although it looks as if there are more. --- libs/pbd/windows_special_dirs.cc | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) (limited to 'libs/pbd/windows_special_dirs.cc') diff --git a/libs/pbd/windows_special_dirs.cc b/libs/pbd/windows_special_dirs.cc index 5e924f57e1..d5138050df 100644 --- a/libs/pbd/windows_special_dirs.cc +++ b/libs/pbd/windows_special_dirs.cc @@ -23,38 +23,27 @@ #include "pbd/windows_special_dirs.h" -//*************************************************************** -// -// get_win_special_folder() -// -// Gets the full path name that corresponds of one of the Windows -// special folders, such as "My Documents" and the like. The input -// parameter must be one of the corresponding CSIDL values, such -// as CSIDL_SYSTEM etc. -// -// Returns: -// -// On Success: A pointer to a newly allocated string containing -// the name of the special folder (must later be freed). -// On Failure: NULL -// - -char * -PBD::get_win_special_folder (int csidl) +std::string +PBD::get_win_special_folder_path (int csidl) { wchar_t path[PATH_MAX+1]; HRESULT hr; LPITEMIDLIST pidl = 0; - char *retval = 0; + char *utf8_folder_path = 0; if (S_OK == (hr = SHGetSpecialFolderLocation (0, csidl, &pidl))) { if (SHGetPathFromIDListW (pidl, path)) { - retval = g_utf16_to_utf8 ((const gunichar2*)path, -1, 0, 0, 0); + utf8_folder_path = g_utf16_to_utf8 ((const gunichar2*)path, -1, 0, 0, 0); } CoTaskMemFree (pidl); } - return retval; + if (utf8_folder_path != NULL) { + std::string folder_path(utf8_folder_path); + g_free (utf8_folder_path); + return folder_path; + } + return std::string(); } -- cgit v1.2.3