[Spice-devel,v2,3/6] red_get_image_data_flat: allocate mem after sanity check

Submitted by Uri Lublin on Dec. 6, 2016, 4:06 p.m.

Details

Message ID 20161206160631.30624-4-uril@redhat.com
State Accepted
Headers show
Series "More coverity fixes" ( rev: 3 ) in Spice

Not browsing as part of any series.

Commit Message

Uri Lublin Dec. 6, 2016, 4:06 p.m.
This patch prevents possible memory leak.

Found by coverity.

Signed-off-by: Uri Lublin <uril@redhat.com>
---
 server/red-parse-qxl.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/server/red-parse-qxl.c b/server/red-parse-qxl.c
index 11da3a1..89cb120 100644
--- a/server/red-parse-qxl.c
+++ b/server/red-parse-qxl.c
@@ -371,13 +371,16 @@  static SpiceChunks *red_get_image_data_flat(RedMemSlotInfo *slots, int group_id,
 {
     SpiceChunks *data;
     int error;
+    unsigned long bitmap_virt;
+
+    bitmap_virt = memslot_get_virt(slots, addr, size, group_id, &error);
+    if (error) {
+        return 0;
+    }
 
     data = spice_chunks_new(1);
     data->data_size      = size;
-    data->chunk[0].data  = (void*)memslot_get_virt(slots, addr, size, group_id, &error);
-    if (error) {
-        return 0;
-    }
+    data->chunk[0].data  = (void*)bitmap_virt;
     data->chunk[0].len   = size;
     return data;
 }

Comments

> 
> This patch prevents possible memory leak.
> 
> Found by coverity.
> 
> Signed-off-by: Uri Lublin <uril@redhat.com>
> ---
>  server/red-parse-qxl.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/server/red-parse-qxl.c b/server/red-parse-qxl.c
> index 11da3a1..89cb120 100644
> --- a/server/red-parse-qxl.c
> +++ b/server/red-parse-qxl.c
> @@ -371,13 +371,16 @@ static SpiceChunks
> *red_get_image_data_flat(RedMemSlotInfo *slots, int group_id,
>  {
>      SpiceChunks *data;
>      int error;
> +    unsigned long bitmap_virt;
> +
> +    bitmap_virt = memslot_get_virt(slots, addr, size, group_id, &error);
> +    if (error) {
> +        return 0;
> +    }
>  
>      data = spice_chunks_new(1);
>      data->data_size      = size;
> -    data->chunk[0].data  = (void*)memslot_get_virt(slots, addr, size,
> group_id, &error);
> -    if (error) {
> -        return 0;
> -    }
> +    data->chunk[0].data  = (void*)bitmap_virt;
>      data->chunk[0].len   = size;
>      return data;
>  }

Would still prefer LLP64 compatibility but all memslot is not either.
Maybe a follow up.

Acked-by: Frediano Ziglio <fziglio@redhat.com>

Frediano