[gupnp-tools] upload: Minor autoptr stuff
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gupnp-tools] upload: Minor autoptr stuff
- Date: Mon, 10 Oct 2022 22:04:13 +0000 (UTC)
commit 71cae570f847f092e3d9421b1cc4affedb66a430
Author: Jens Georg <mail jensge org>
Date: Fri Jun 3 19:30:56 2022 +0200
upload: Minor autoptr stuff
src/upload/container-search.c | 18 +++---------------
src/upload/main.c | 15 ++++-----------
src/upload/transfer.c | 8 ++++----
3 files changed, 11 insertions(+), 30 deletions(-)
---
diff --git a/src/upload/container-search.c b/src/upload/container-search.c
index d584be1..c7285cd 100644
--- a/src/upload/container-search.c
+++ b/src/upload/container-search.c
@@ -74,9 +74,9 @@ parse_result (const char *result)
static void
browse_cb (GObject *object, GAsyncResult *res, gpointer user_data)
{
- GError *error = NULL;
- char *result = NULL;
- char *container_id = NULL;
+ g_autoptr (GError) error = NULL;
+ g_autofree char *result = NULL;
+ g_autofree char *container_id = NULL;
GUPnPServiceProxyAction *action = NULL;
GUPnPServiceProxy *proxy = GUPNP_SERVICE_PROXY (object);
@@ -85,9 +85,6 @@ browse_cb (GObject *object, GAsyncResult *res, gpointer user_data)
if (error != NULL) {
g_critical ("Failed to browse root container: %s",
error->message);
-
- g_error_free (error);
-
application_exit ();
return;
@@ -102,9 +99,6 @@ browse_cb (GObject *object, GAsyncResult *res, gpointer user_data)
if (error != NULL) {
g_critical ("Failed to browse root container: %s",
error->message);
-
- g_error_free (error);
-
application_exit ();
return;
@@ -115,17 +109,11 @@ browse_cb (GObject *object, GAsyncResult *res, gpointer user_data)
container_id = parse_result (result);
if (container_id == NULL) {
g_critical ("Failed to find a suitable container for upload.");
- g_free (result);
application_exit ();
-
- return;
} else {
container_found (container_id);
- g_free (container_id);
}
-
- g_free (result);
}
void
diff --git a/src/upload/main.c b/src/upload/main.c
index a47cb1e..4e80592 100644
--- a/src/upload/main.c
+++ b/src/upload/main.c
@@ -134,13 +134,9 @@ gint
main (gint argc,
gchar *argv[])
{
- GError *error = NULL;
+ g_autoptr (GError) error = NULL;
gint i;
- GOptionContext *context;
-
-#if !GLIB_CHECK_VERSION(2, 35, 0)
- g_type_init ();
-#endif
+ g_autoptr (GOptionContext) context;
context = g_option_context_new ("- Upload files to UPnP MediaServer");
g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
@@ -151,11 +147,10 @@ main (gint argc,
}
if (argc < 2) {
- char *help = NULL;
+ g_autofree char *help = NULL;
help = g_option_context_get_help (context, TRUE, NULL);
g_print ("%s\n", help);
- g_free (help);
return -4;
}
@@ -184,8 +179,7 @@ main (gint argc,
upnp_context = gupnp_context_new (interface, 0, &error);
if (error) {
g_printerr ("Error creating the GUPnP context: %s\n",
- error->message);
- g_error_free (error);
+ error->message);
return -6;
}
@@ -206,7 +200,6 @@ main (gint argc,
g_clear_pointer (&main_loop, g_main_loop_unref);
deinit_control_point ();
g_object_unref (upnp_context);
- g_option_context_free (context);
g_free (dest_container);
g_free (interface);
diff --git a/src/upload/transfer.c b/src/upload/transfer.c
index 64e645b..f1b2d48 100644
--- a/src/upload/transfer.c
+++ b/src/upload/transfer.c
@@ -40,15 +40,14 @@ get_transfer_progress_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
- GError *error;
+ g_autoptr (GError) error = NULL;
TrackTransferData *data;
- guint64 total, length;
- gchar *status;
+ guint64 total = 0, length = 0;
+ g_autofree gchar *status = NULL;
GUPnPServiceProxyAction *action;
data = (TrackTransferData *) user_data;
- error = NULL;
total = length = 0;
status = NULL;
action = gupnp_service_proxy_call_action_finish (
@@ -58,6 +57,7 @@ get_transfer_progress_cb (GObject *object,
if (error == NULL) {
gupnp_service_proxy_action_get_result (action, &error, NULL);
}
+
if (error != NULL) {
g_critical ("Failed to track file transfer: %s",
error->message);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]