[libcroco/wip/fmuellner/coverage-fixes: 4/12] num: Don't leak duped num objects on failure



commit 76867f0c57bdc72ea826b8298d32a61701e7a0b4
Author: Florian Müllner <fmuellner gnome org>
Date:   Tue Feb 19 00:04:59 2019 +0100

    num: Don't leak duped num objects on failure
    
    cr_num_dup() may fail and return NULL. The previously allocated
    memory should be freed in that case.
    
    Spotted by covscan.
    
    https://gitlab.gnome.org/GNOME/libcroco/merge_requests/1

 src/cr-num.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
---
diff --git a/src/cr-num.c b/src/cr-num.c
index d5dbd5f..8b0cc42 100644
--- a/src/cr-num.c
+++ b/src/cr-num.c
@@ -245,7 +245,8 @@ cr_num_dup (CRNum const * a_this)
         g_return_val_if_fail (result, NULL);
 
         status = cr_num_copy (result, a_this);
-        g_return_val_if_fail (status == CR_OK, NULL);
+        if (status != CR_OK)
+                g_clear_pointer (&result, cr_num_destroy);
 
         return result;
 }


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