[gjs: 2/3] cairo: Don't free unowned Cairo structs



commit 0038bf9ada40f439f018e7e4e04e5c68cd2aca16
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Apr 20 15:26:34 2019 -0700

    cairo: Don't free unowned Cairo structs
    
    It seems that in all other release functions, we don't free the
    GIArgument's data in the transfer-none case. That would end up freeing
    a passed-in argument that was owned by the caller, or a return value
    that was owned by the callee.
    
    This bug was spotted by compiling with -Wunused-parameter.

 modules/cairo-context.cpp | 3 ++-
 modules/cairo-region.cpp  | 3 ++-
 modules/cairo-surface.cpp | 3 ++-
 3 files changed, 6 insertions(+), 3 deletions(-)
---
diff --git a/modules/cairo-context.cpp b/modules/cairo-context.cpp
index 21467ff6..e8b00d75 100644
--- a/modules/cairo-context.cpp
+++ b/modules/cairo-context.cpp
@@ -1024,7 +1024,8 @@ context_release_argument(JSContext  *context,
                          GITransfer  transfer,
                          GArgument  *arg)
 {
-    cairo_destroy((cairo_t*)arg->v_pointer);
+    if (transfer != GI_TRANSFER_NOTHING)
+        cairo_destroy(static_cast<cairo_t*>(arg->v_pointer));
     return true;
 }
 
diff --git a/modules/cairo-region.cpp b/modules/cairo-region.cpp
index 33fbe86d..743ae17a 100644
--- a/modules/cairo-region.cpp
+++ b/modules/cairo-region.cpp
@@ -360,7 +360,8 @@ region_release_argument(JSContext  *context,
                         GITransfer  transfer,
                         GArgument  *arg)
 {
-    cairo_region_destroy((cairo_region_t*)arg->v_pointer);
+    if (transfer != GI_TRANSFER_NOTHING)
+        cairo_region_destroy(static_cast<cairo_region_t*>(arg->v_pointer));
     return true;
 }
 
diff --git a/modules/cairo-surface.cpp b/modules/cairo-surface.cpp
index b726db50..529ef059 100644
--- a/modules/cairo-surface.cpp
+++ b/modules/cairo-surface.cpp
@@ -302,7 +302,8 @@ surface_release_argument(JSContext  *context,
                          GITransfer  transfer,
                          GArgument  *arg)
 {
-    cairo_surface_destroy((cairo_surface_t*)arg->v_pointer);
+    if (transfer != GI_TRANSFER_NOTHING)
+        cairo_surface_destroy(static_cast<cairo_surface_t*>(arg->v_pointer));
     return true;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]