summaryrefslogtreecommitdiff
path: root/src/libical-glib
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2019-10-14 21:23:20 +0200
committerCorentin Noël <corentin@elementary.io>2019-10-15 18:45:40 +0200
commit57e4b56fac028f83b7a467001ea982b47ab44580 (patch)
tree02092298900dbc9a0d44c6a2f1476191df5ba1ca /src/libical-glib
parentf3239364efcd91ba29c79e4122820805660138b3 (diff)
downloadlibical-git-57e4b56fac028f83b7a467001ea982b47ab44580.tar.gz
Let icalattach_new_from_data() use the 'free_fn' argument againmcrha/annotations
This had been disabled with commit 7a2f318bacae5521848963d96a3a644bc6be1d01 (in time of 1.0.1) to fix inline attachments crashing. That commit could eventually cause memory leaks and higher memory usage. This change adds necessary strdup() calls on places where required only and makes use of the 'free_fn' argument again. It also fixes libical-glib's i_cal_attach_new_from_bytes(), which relies on this 'free_fn'.
Diffstat (limited to 'src/libical-glib')
-rw-r--r--src/libical-glib/api/i-cal-attach.xml22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/libical-glib/api/i-cal-attach.xml b/src/libical-glib/api/i-cal-attach.xml
index e4fcf0d2..c77c0102 100644
--- a/src/libical-glib/api/i-cal-attach.xml
+++ b/src/libical-glib/api/i-cal-attach.xml
@@ -19,27 +19,41 @@
<returns type="ICalAttach *" annotation="transfer full" comment="The newly created #ICalAttach from the @url" />
<comment xml:space="preserve">Create a new #ICalAttach from the url</comment>
</method>
- <method name="i_cal_attach_new_from_data" corresponds="icalattach_new_from_data" kind="constructor" since="1.0">
+ <declaration position="body">
+static void icalglib_free_attach_data(gpointer data, gpointer user_data)
+{
+ _unused(user_data);
+ g_free (data);
+}</declaration>
+ <method name="i_cal_attach_new_from_data" corresponds="CUSTOM" kind="constructor" since="1.0">
<parameter type="const gchar *" name="data" comment="The data used to create the #ICalAttach"/>
<parameter type="GFunc" name="free_fn" translator="(icalattach_free_fn_t)" annotation="scope call, allow-none" comment="The function used to free the data when the create #ICalAttach is detroyed."/>
<parameter type="void *" name="free_fn_data" annotation="allow-none" comment="The userdata used for the free function @free_fn"/>
<returns type="ICalAttach *" annotation="transfer full" comment="The newly created #ICalAttach" />
<comment xml:space="preserve">Create a new #ICalAttach from the data.</comment>
+ <custom> g_return_val_if_fail (data != NULL, NULL);
+
+ if (!free_fn) {
+ data = g_strdup(data);
+ free_fn = icalglib_free_attach_data;
+ }
+
+ return i_cal_attach_new_full (icalattach_new_from_data (data, (icalattach_free_fn_t) (free_fn), free_fn_data), NULL);</custom>
</method>
<declaration position="body">
-static void unref_g_bytes(unsigned char *data, void *user_data)
+static void unref_g_bytes(char *data, void *user_data)
{
GBytes *bytes = user_data;
g_return_if_fail (data != NULL);
g_return_if_fail (bytes != NULL);
- g_bytes_unref (bytes);
+ g_bytes_unref(bytes);
}</declaration>
<method name="i_cal_attach_new_from_bytes" corresponds="CUSTOM" kind="constructor" since="1.0">
<parameter type="GBytes *" annotation="transfer full" name="bytes" comment="The #GBytes holding the data used to create the #ICalAttach"/>
<returns type="ICalAttach *" annotation="transfer full" comment="The newly created #ICalAttach" />
- <comment xml:space="preserve">Create a new #ICalAttach from the data in bytes. Takes a reference of @bytes, increase the reference before calling this function if you with to use it afterward.</comment>
+ <comment xml:space="preserve">Create a new #ICalAttach from the data in bytes. Takes a reference of @bytes, increase the reference before calling this function if you with to use it afterward. The stored bytes should be already encoded with used encoding (like base64).</comment>
<custom> g_return_val_if_fail (bytes != NULL, NULL);
return i_cal_attach_new_full (icalattach_new_from_data (g_bytes_get_data (bytes, NULL), unref_g_bytes, bytes), NULL);</custom>