[gjs: 2/3] function: Free transfer-full in arguments when function fails



commit a2f9ea08a2c0a4b7d6f8e8e18ab8a269c4f17dab
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Mar 16 22:11:40 2019 -0700

    function: Free transfer-full in arguments when function fails
    
    If we fail to marshal the arguments and throw an exception before
    calling a gobject-introspected function, or the function itself throws
    a GError exception, then we can assume that any transfer of ownership
    of a (transfer full) or (transfer container) in-argument was not
    completed.
    
    This means that we have to free any storage that would otherwise have
    had its ownership transferred to the function.

 gi/function.cpp | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
---
diff --git a/gi/function.cpp b/gi/function.cpp
index 9380b62a..ef708f0c 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -1210,7 +1210,15 @@ release:
 
             if (direction == GI_DIRECTION_IN) {
                 arg = &in_arg_cvalues[c_arg_pos];
-                transfer = g_arg_info_get_ownership_transfer(&arg_info);
+
+                // If we failed before calling the function, or if the function
+                // threw an exception, then any GI_TRANSFER_EVERYTHING or
+                // GI_TRANSFER_CONTAINER parameters were not transferred. Treat
+                // them as GI_TRANSFER_NOTHING so that they are freed.
+                if (!failed && !did_throw_gerror)
+                    transfer = g_arg_info_get_ownership_transfer(&arg_info);
+                else
+                    transfer = GI_TRANSFER_NOTHING;
             } else {
                 arg = &inout_original_arg_cvalues[c_arg_pos];
                 /* For inout, transfer refers to what we get back from the function; for


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