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.
This commit is contained in:
Benjamin Berg 2019-11-25 18:41:44 +01:00
parent 14a41bdd48
commit 9b48864c5b

View file

@ -1047,7 +1047,7 @@ fp_print_deserialize (const guchar *data,
fpi_print_set_type (result, FP_PRINT_NBIS); fpi_print_set_type (result, FP_PRINT_NBIS);
for (i = 0; i < g_variant_n_children (prints); i++) 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; const gint32 *xcol, *ycol, *thetacol;
gsize xlen, ylen, thetalen; gsize xlen, ylen, thetalen;
g_autoptr(GVariant) xyt_data = NULL; 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->ycol, ycol, sizeof (xcol[0]) * xlen);
memcpy (xyt->thetacol, thetacol, 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) else if (type == FP_PRINT_RAW)