Make escape() return a wcstring

This avoids the potential for leaking the resulting string.
This commit is contained in:
Kevin Ballard
2014-09-25 18:20:03 -07:00
parent cd4fa518b8
commit 35595dbffd
7 changed files with 23 additions and 33 deletions

View File

@@ -49,7 +49,7 @@ static kill_list_t kill_list;
/**
Contents of the X clipboard, at last time we checked it
*/
static wchar_t *cut_buffer=0;
static wcstring cut_buffer;
/**
Test if the xsel command is installed. Since this is called often,
@@ -73,7 +73,7 @@ void kill_add(const wcstring &str)
return;
wcstring cmd;
wchar_t *escaped_str = NULL;
wcstring escaped_str;
kill_list.push_front(str);
/*
@@ -87,7 +87,7 @@ void kill_add(const wcstring &str)
const env_var_t clipboard_wstr = env_get_string(L"FISH_CLIPBOARD_CMD");
if (!clipboard_wstr.missing())
{
escaped_str = escape(str.c_str(), 1);
escaped_str = escape(str.c_str(), ESCAPE_ALL);
cmd.assign(L"echo -n ");
cmd.append(escaped_str);
cmd.append(clipboard_wstr);
@@ -119,8 +119,6 @@ void kill_add(const wcstring &str)
*/
}
free(cut_buffer);
cut_buffer = escaped_str;
}
}
@@ -193,10 +191,9 @@ static void kill_check_x_buffer()
etc. anyway.
*/
if (cut_buffer == NULL || cut_buffer != new_cut_buffer)
if (cut_buffer != new_cut_buffer)
{
free(cut_buffer);
cut_buffer = wcsdup(new_cut_buffer.c_str());
cut_buffer = new_cut_buffer;
kill_list.push_front(new_cut_buffer);
}
}
@@ -228,7 +225,6 @@ void kill_init()
void kill_destroy()
{
if (cut_buffer)
free(cut_buffer);
cut_buffer.clear();
}