Blob Blame History Raw
From 9b48864c5b41111e1c6f40c1623b0f2393c3cc58 Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Mon, 25 Nov 2019 18:41:44 +0100
Subject: [PATCH 009/181] print: Ensure xyt struct is not leaked during
 deserialization

In the unlikely event of an error, the variable may have been leaked.
Fix this by using g_autoptr combined with a g_steal_pointer.
---
 libfprint/fp-print.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libfprint/fp-print.c b/libfprint/fp-print.c
index 592be14..1a6a70f 100644
--- a/libfprint/fp-print.c
+++ b/libfprint/fp-print.c
@@ -1047,7 +1047,7 @@ fp_print_deserialize (const guchar *data,
       fpi_print_set_type (result, FP_PRINT_NBIS);
       for (i = 0; i < g_variant_n_children (prints); i++)
         {
-          struct xyt_struct *xyt = g_new0 (struct xyt_struct, 1);
+          g_autofree struct xyt_struct *xyt = g_new0 (struct xyt_struct, 1);
           const gint32 *xcol, *ycol, *thetacol;
           gsize xlen, ylen, thetalen;
           g_autoptr(GVariant) xyt_data = NULL;
@@ -1078,7 +1078,7 @@ fp_print_deserialize (const guchar *data,
           memcpy (xyt->ycol, ycol, sizeof (xcol[0]) * xlen);
           memcpy (xyt->thetacol, thetacol, sizeof (xcol[0]) * xlen);
 
-          g_ptr_array_add (result->prints, xyt);
+          g_ptr_array_add (result->prints, g_steal_pointer (&xyt));
         }
     }
   else if (type == FP_PRINT_RAW)
-- 
2.24.1