diff options
author | Hans de Goede <hdegoede@redhat.com> | 2010-10-04 12:10:47 +0200 |
---|---|---|
committer | Hans de Goede <hdegoede@redhat.com> | 2010-10-04 14:41:23 +0200 |
commit | ff434c288f87a1a08a2cf1e58260daea68914769 (patch) | |
tree | 51dcc502e4770ef8c23d76e9d232d9acc086bb07 | |
parent | 348e62bd88f63f5d841fb79d747a340076c408f4 (diff) | |
download | spice-ff434c288f87a1a08a2cf1e58260daea68914769.tar.gz spice-ff434c288f87a1a08a2cf1e58260daea68914769.tar.xz spice-ff434c288f87a1a08a2cf1e58260daea68914769.zip |
spicec-x11: use malloc / free / realloc for clipboard data
As we need a realloc function it is better to use malloc / free /
realloc then to diy, esp. as realloc can grow the buffer without
needing a memcpy.
-rw-r--r-- | client/x11/platform.cpp | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/client/x11/platform.cpp b/client/x11/platform.cpp index 981bdc0b..dc0787f0 100644 --- a/client/x11/platform.cpp +++ b/client/x11/platform.cpp @@ -2265,28 +2265,13 @@ void Platform::path_append(std::string& path, const std::string& partial_path) static void ensure_clipboard_data_space(uint32_t size) { if (size > clipboard_data_space) { - delete clipboard_data; - clipboard_data = NULL; - clipboard_data = new uint8_t[size]; + free(clipboard_data); + clipboard_data = (uint8_t *)malloc(size); assert(clipboard_data); clipboard_data_space = size; } } -static void realloc_clipboard_data_space(uint32_t size) -{ - if (size <= clipboard_data_space) { - return; - } - uint32_t old_alloc = clipboard_data_space; - clipboard_data_space = size; - uint8_t *newbuf = new uint8_t[clipboard_data_space]; - assert(newbuf); - memcpy(newbuf, clipboard_data, old_alloc); - delete[] clipboard_data; - clipboard_data = newbuf; -} - static void send_selection_notify(Atom prop, int process_next_req) { XEvent res, *event = &next_selection_request->event; @@ -2425,8 +2410,11 @@ static int get_selection(XEvent &event, Atom type, Atom prop, int format, if (incr) { if (len) { - if (clipboard_data_size + len > clipboard_data_space) - realloc_clipboard_data_space(clipboard_data_size + len); + if (clipboard_data_size + len > clipboard_data_space) { + clipboard_data_space = clipboard_data_size + len; + clipboard_data = (uint8_t *)realloc(clipboard_data, clipboard_data_space); + assert(clipboard_data); + } memcpy(clipboard_data + clipboard_data_size, data, len); clipboard_data_size += len; LOG_INFO("Appended %d bytes to buffer", len); |