[glib/wip/sadiq/improve-gvariant-docs] docs: Improve GVariant docs




commit 1953505abae279fe21695f0c57faf872d67dfa98
Author: Mohammed Sadiq <sadiq sadiqpk org>
Date:   Sun Nov 28 12:55:57 2021 +0530

    docs: Improve GVariant docs
    
    Fix a typo and expand examples to include freeing memory
    where it's not obvious

 docs/reference/glib/gvariant-varargs.xml | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/docs/reference/glib/gvariant-varargs.xml b/docs/reference/glib/gvariant-varargs.xml
index bab12e31e..11b49e7ff 100644
--- a/docs/reference/glib/gvariant-varargs.xml
+++ b/docs/reference/glib/gvariant-varargs.xml
@@ -658,6 +658,7 @@ g_variant_builder_unref (builder);
   gchar *str;
 
   g_variant_get (value, "as", &iter);
+  /* No need to free 'str' unless breaking out of the loop */
   while (g_variant_iter_loop (iter, "s", &str))
     g_print ("%s\n", str);
   g_variant_iter_free (iter);
@@ -878,7 +879,10 @@ value2 = g_variant_new ("(@(iii)*)", value1, g_variant_new_string ("foo"));
   g_variant_get (value2, "(rs)", NULL, &string); /* or "(@(iii)s)" */
   g_print ("i only got the string: %s\n", string);
   g_free (string);
-}]]></programlisting></informalexample>
+}
+
+g_variant_unref (value2);
+/* no need to free 'value1' */]]></programlisting></informalexample>
    </refsect3>
   </refsect2>
 
@@ -917,7 +921,7 @@ dict = g_variant_builder_end (b);]]></programlisting></informalexample>
 gint value = 1;
 gint max = 3;
 
-/* type (oa{sa{sv}) */
+/* type (oa{sa{sv}}) */
 data = g_variant_new_parsed ("(%o, {'brightness': {'value': <%i>, 'max': <%i>}})",
                              "/object/path", value, max);
 {
@@ -928,10 +932,12 @@ data = g_variant_new_parsed ("(%o, {'brightness': {'value': <%i>, 'max': <%i>}})
 
   g_variant_get (data, "(o@a{?*})", &obj, &params);
   g_print ("object_path: %s\n", obj);
+  g_free (obj);
 
   p_brightness = g_variant_lookup_value (params, "brightness", G_VARIANT_TYPE_VARDICT);
   g_variant_lookup (p_brightness, "max", "i", &p_max);
   g_print ("max: %d\n", p_max);
+  g_variant_unref (params);
 }]]></programlisting></informalexample>
    </refsect3>
 


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