diff options
author | Milan Crha <mcrha@redhat.com> | 2019-10-14 21:23:20 +0200 |
---|---|---|
committer | Corentin Noël <corentin@elementary.io> | 2019-10-15 18:45:40 +0200 |
commit | 57e4b56fac028f83b7a467001ea982b47ab44580 (patch) | |
tree | 02092298900dbc9a0d44c6a2f1476191df5ba1ca /src/libical/icalattach.c | |
parent | f3239364efcd91ba29c79e4122820805660138b3 (diff) | |
download | libical-git-mcrha/annotations.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/icalattach.c')
-rw-r--r-- | src/libical/icalattach.c | 17 |
1 files changed, 3 insertions, 14 deletions
diff --git a/src/libical/icalattach.c b/src/libical/icalattach.c index e5c3a097..d66a67f7 100644 --- a/src/libical/icalattach.c +++ b/src/libical/icalattach.c @@ -55,7 +55,6 @@ icalattach *icalattach_new_from_data(const char *data, icalattach_free_fn_t free void *free_fn_data) { icalattach *attach; - char *data_copy; icalerror_check_arg_rz((data != NULL), "data"); @@ -64,15 +63,9 @@ icalattach *icalattach_new_from_data(const char *data, icalattach_free_fn_t free return NULL; } - if ((data_copy = strdup(data)) == NULL) { - free(attach); - errno = ENOMEM; - return NULL; - } - attach->refcount = 1; attach->is_url = 0; - attach->u.data.data = data_copy; + attach->u.data.data = (char *) data; attach->u.data.free_fn = free_fn; attach->u.data.free_fn_data = free_fn_data; @@ -99,12 +92,8 @@ void icalattach_unref(icalattach *attach) if (attach->is_url) { free(attach->u.url.url); - } else { - free(attach->u.data.data); -/* unused for now - if (attach->u.data.free_fn) - (* attach->u.data.free_fn) (attach->u.data.data, attach->u.data.free_fn_data); -*/ + } else if (attach->u.data.free_fn) { + (* attach->u.data.free_fn) (attach->u.data.data, attach->u.data.free_fn_data); } free(attach); |