vbo/dlist: free copied.buffer if no vertices were copied
authorPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Mon, 4 Oct 2021 09:18:47 +0000 (11:18 +0200)
committerPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Thu, 4 Nov 2021 12:59:00 +0000 (13:59 +0100)
Other parts of the code asserts that copied.buffer is NULL if there are
no vertices to copy.

Cc: mesa-stable
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13246>

src/mesa/vbo/vbo_save_api.c

index 6bcd3e9..e71613c 100644 (file)
@@ -168,8 +168,13 @@ copy_vertices(struct gl_context *ctx,
    assert(save->copied.buffer == NULL);
    save->copied.buffer = malloc(sizeof(fi_type) * sz * prim->count);
 
-   return vbo_copy_vertices(ctx, prim->mode, prim->start, &prim->count,
-                            prim->begin, sz, true, save->copied.buffer, src);
+   unsigned r = vbo_copy_vertices(ctx, prim->mode, prim->start, &prim->count,
+                                  prim->begin, sz, true, save->copied.buffer, src);
+   if (!r) {
+      free(save->copied.buffer);
+      save->copied.buffer = NULL;
+   }
+   return r;
 }