about summary refs log tree commit diff stats
path: root/src/tools
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2023-05-12 08:40:51 +0200
committerGitHub <noreply@github.com>2023-05-12 08:40:51 +0200
commit879525c61b8ec540279a58cffe19dd2fab668c2f (patch)
tree7f05070275d5cc3405cbe9ca7f7305a9aeaf8151 /src/tools
parentf3265565e853ecf993f12093c6a0c94acf3f212e (diff)
parentd8eea87f6001ef6ba1b2b4c127a6b090ed00226e (diff)
downloadprofani-tty-879525c61b8ec540279a58cffe19dd2fab668c2f.tar.gz
Merge pull request #1848 from profanity-im/minor-improvements
Minor improvements
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/editor.c20
1 files changed, 5 insertions, 15 deletions
diff --git a/src/tools/editor.c b/src/tools/editor.c
index 0efb4d6b..4cd70d9d 100644
--- a/src/tools/editor.c
+++ b/src/tools/editor.c
@@ -54,19 +54,18 @@ get_message_from_editor(gchar* message, gchar** returned_message)
     /* Make sure that there's no junk in the return-pointer in error cases */
     *returned_message = NULL;
 
-    gchar* filename = NULL;
+    auto_gchar gchar* filename = NULL;
     GError* glib_error = NULL;
     auto_char char* jid = connection_get_barejid();
     if (jid) {
         filename = files_file_in_account_data_path(DIR_EDITOR, jid, "compose.md");
     } else {
         log_debug("[Editor] could not get JID");
-        gchar* data_dir = files_get_data_path(DIR_EDITOR);
+        auto_gchar gchar* data_dir = files_get_data_path(DIR_EDITOR);
         if (!create_dir(data_dir)) {
             return TRUE;
         }
         filename = g_strdup_printf("%s/compose.md", data_dir);
-        g_free(data_dir);
     }
     if (!filename) {
         log_error("[Editor] something went wrong while creating compose file");
@@ -83,21 +82,17 @@ get_message_from_editor(gchar* message, gchar** returned_message)
         if (glib_error) {
             g_error_free(glib_error);
         }
-        g_free(filename);
         return TRUE;
     }
 
-    char* editor = prefs_get_string(PREF_COMPOSE_EDITOR);
-    gchar* editor_with_filename = g_strdup_printf("%s %s", editor, filename);
-    gchar** editor_argv = g_strsplit(editor_with_filename, " ", 0);
-
-    g_free(editor_with_filename);
+    auto_gchar gchar* editor = prefs_get_string(PREF_COMPOSE_EDITOR);
+    auto_gchar gchar* editor_with_filename = g_strdup_printf("%s %s", editor, filename);
+    auto_gcharv gchar** editor_argv = g_strsplit(editor_with_filename, " ", 0);
 
     // Fork / exec
     pid_t pid = fork();
     if (pid == 0) {
         int x = execvp(editor_argv[0], editor_argv);
-        g_strfreev(editor_argv);
         if (x == -1) {
             log_error("[Editor] Failed to exec %s", editor);
         }
@@ -115,8 +110,6 @@ get_message_from_editor(gchar* message, gchar** returned_message)
             if (glib_error) {
                 g_error_free(glib_error);
             }
-            g_free(filename);
-            g_free(editor);
             return TRUE;
         }
         /* Remove all trailing new-line characters */
@@ -127,10 +120,7 @@ get_message_from_editor(gchar* message, gchar** returned_message)
         } else {
             log_debug("[Editor] deleted file: %s", filename);
         }
-        g_free(filename);
     }
 
-    g_free(editor);
-
     return FALSE;
 }