aboutsummaryrefslogtreecommitdiffhomepage
path: root/kill.cpp
diff options
context:
space:
mode:
authorGravatar Kevin Ballard <kevin@sb.org>2014-09-25 18:20:03 -0700
committerGravatar Kevin Ballard <kevin@sb.org>2014-09-25 18:20:03 -0700
commit35595dbffdf413694b31da46129432ef345921af (patch)
treee78b379cf7854b1a8402f8da267e8f6d84450c6f /kill.cpp
parentcd4fa518b86ddfb3e946fa4dd69e9e32a58ef81e (diff)
Make escape() return a wcstring
This avoids the potential for leaking the resulting string.
Diffstat (limited to 'kill.cpp')
-rw-r--r--kill.cpp16
1 files changed, 6 insertions, 10 deletions
diff --git a/kill.cpp b/kill.cpp
index 6ae27c51..0033ca2f 100644
--- a/kill.cpp
+++ b/kill.cpp
@@ -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();
}