[gvfs/mtp-backend: 60/64] MTP: Review Feedback: Fix memory leaks and improve memory management.
- From: Philip Langdale <philipl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gvfs/mtp-backend: 60/64] MTP: Review Feedback: Fix memory leaks and improve memory management.
- Date: Sat, 12 Jan 2013 04:39:11 +0000 (UTC)
commit 53863b515e3748354d45d204b5fcca878222342a
Author: Philip Langdale <philipl overt org>
Date: Thu Jan 3 21:05:28 2013 -0800
MTP: Review Feedback: Fix memory leaks and improve memory management.
daemon/gvfsbackendmtp.c | 23 +++++++++++------------
monitor/mtp/gmtpvolume.c | 9 +++------
monitor/mtp/gmtpvolumemonitor.c | 4 ++--
3 files changed, 16 insertions(+), 20 deletions(-)
---
diff --git a/daemon/gvfsbackendmtp.c b/daemon/gvfsbackendmtp.c
index 0cfd15c..245916d 100644
--- a/daemon/gvfsbackendmtp.c
+++ b/daemon/gvfsbackendmtp.c
@@ -585,6 +585,7 @@ get_device (GVfsBackend *backend, const char *id, GVfsJob *job) {
LIBMTP_Dump_Errorstack (device);
LIBMTP_Clear_Errorstack (device);
+ g_free (name);
break;
} else {
g_free (name);
@@ -1110,16 +1111,15 @@ do_pull (GVfsBackend *backend,
_("Can't recursively copy directory"));
goto exit;
} else {
- MtpProgressData *mtp_progress_data = g_new0 (MtpProgressData, 1);
- mtp_progress_data->progress_callback = progress_callback;
- mtp_progress_data->progress_callback_data = progress_callback_data;
- mtp_progress_data->job = G_VFS_JOB (job);
+ MtpProgressData mtp_progress_data;
+ mtp_progress_data.progress_callback = progress_callback;
+ mtp_progress_data.progress_callback_data = progress_callback_data;
+ mtp_progress_data.job = G_VFS_JOB (job);
int ret = LIBMTP_Get_File_To_File (device,
strtol (elements[ne-1], NULL, 10),
local_path,
(LIBMTP_progressfunc_t)mtp_progress,
- mtp_progress_data);
- g_free (mtp_progress_data);
+ &mtp_progress_data);
if (ret != 0) {
fail_job (G_VFS_JOB (job), device);
goto exit;
@@ -1200,14 +1200,13 @@ do_push (GVfsBackend *backend,
mtpfile->filetype = LIBMTP_FILETYPE_UNKNOWN;
mtpfile->filesize = g_file_info_get_size (info);
- MtpProgressData *mtp_progress_data = g_new0 (MtpProgressData, 1);
- mtp_progress_data->progress_callback = progress_callback;
- mtp_progress_data->progress_callback_data = progress_callback_data;
- mtp_progress_data->job = G_VFS_JOB (job);
+ MtpProgressData mtp_progress_data;
+ mtp_progress_data.progress_callback = progress_callback;
+ mtp_progress_data.progress_callback_data = progress_callback_data;
+ mtp_progress_data.job = G_VFS_JOB (job);
int ret = LIBMTP_Send_File_From_File (device, local_path, mtpfile,
(LIBMTP_progressfunc_t)mtp_progress,
- mtp_progress_data);
- g_free (mtp_progress_data);
+ &mtp_progress_data);
LIBMTP_destroy_file_t (mtpfile);
if (ret != 0) {
fail_job (G_VFS_JOB (job), device);
diff --git a/monitor/mtp/gmtpvolume.c b/monitor/mtp/gmtpvolume.c
index 3704557..07d8674 100644
--- a/monitor/mtp/gmtpvolume.c
+++ b/monitor/mtp/gmtpvolume.c
@@ -62,11 +62,8 @@ g_mtp_volume_finalize (GObject *object)
volume = G_MTP_VOLUME (object);
- if (volume->device != NULL)
- g_object_unref (volume->device);
-
- if (volume->activation_root != NULL)
- g_object_unref (volume->activation_root);
+ g_clear_object (&volume->device);
+ g_clear_object (&volume->activation_root);
if (volume->volume_monitor != NULL)
g_object_remove_weak_pointer (G_OBJECT (volume->volume_monitor), (gpointer) &(volume->volume_monitor));
@@ -162,7 +159,7 @@ set_volume_name (GMtpVolume *v)
if (model != NULL) {
/* we can't call udev_decode_string() twice in one g_strdup_printf(),
* it returns a static buffer */
- gchar *temp = g_strdup_printf ("%s %s", vendor, model);
+ gchar *temp = g_strconcat (vendor, " ", model, NULL);
v->name = g_strdup (udev_decode_string (temp));
g_free (temp);
} else {
diff --git a/monitor/mtp/gmtpvolumemonitor.c b/monitor/mtp/gmtpvolumemonitor.c
index 2dccba8..bf483fb 100644
--- a/monitor/mtp/gmtpvolumemonitor.c
+++ b/monitor/mtp/gmtpvolumemonitor.c
@@ -62,8 +62,7 @@ G_DEFINE_TYPE (GMtpVolumeMonitor, g_mtp_volume_monitor, G_TYPE_VOLUME_MONITOR)
static void
list_free (GList *objects)
{
- g_list_foreach (objects, (GFunc)g_object_unref, NULL);
- g_list_free (objects);
+ g_list_free_full (objects, g_object_unref);
}
static void
@@ -234,6 +233,7 @@ gudev_coldplug_devices (GMtpVolumeMonitor *monitor)
if (g_udev_device_has_property (d, "ID_MTP_DEVICE"))
gudev_add_device (monitor, d, FALSE);
}
+ g_list_free_full(usb_devices, g_object_unref);
}
static GObject *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]