From 36a81133807e057e065c5f42383239e2f078312c Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <kraxel@redhat.com>
Date: Fri, 27 Aug 2010 08:43:44 +0200
Subject: [PATCH] red_get_cursor: avoid extra copy


Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 server/red_parse_qxl.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/server/red_parse_qxl.c b/server/red_parse_qxl.c
index 6fa6ac5..e6e700b 100644
--- a/server/red_parse_qxl.c
+++ b/server/red_parse_qxl.c
@@ -1009,11 +1009,11 @@ static void red_get_cursor(RedMemSlotInfo *slots, int group_id,
                                    &chunks, &qxl->chunk);
     data = red_linearize_chunk(&chunks, size, &free_data);
     red_put_data_chunks(&chunks);
-    red->data = spice_malloc(size);
-    memcpy(red->data, data, size);
-
     if (free_data) {
-        free(data);
+        red->data = data;
+    } else {
+        red->data = spice_malloc(size);
+        memcpy(red->data, data, size);
     }
 }
 
-- 
1.7.1
