Browse Source

(vfs_get_current_dir): avoid string duplication.

(vfs_get_current_dir_n): new function returned newly allocated string.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Andrew Borodin 9 years ago
parent
commit
3e622b822e
5 changed files with 22 additions and 12 deletions
  1. 1 2
      lib/vfs/path.c
  2. 15 2
      lib/vfs/vfs.c
  3. 2 1
      lib/vfs/vfs.h
  4. 1 2
      src/filemanager/midnight.c
  5. 3 5
      src/filemanager/usermenu.c

+ 1 - 2
lib/vfs/path.c

@@ -156,11 +156,10 @@ vfs_canon (const char *path)
         }
         else
         {
-            char *curr_dir;
+            const char *curr_dir;
 
             curr_dir = vfs_get_current_dir ();
             local = mc_build_filename (curr_dir, path, NULL);
-            g_free (curr_dir);
         }
         result = vfs_canon (local);
         g_free (local);

+ 15 - 2
lib/vfs/vfs.c

@@ -364,11 +364,24 @@ vfs_translate_path_n (const char *path)
 /**
  * Get current directory without any OS calls.
  *
- * @return string contain current path
+ * @return string contains current path
  */
 
-char *
+const char *
 vfs_get_current_dir (void)
+{
+    return current_path->str;
+}
+
+/* --------------------------------------------------------------------------------------------- */
+/**
+ * Get current directory without any OS calls.
+ *
+ * @return newly allocated string contains current path
+ */
+
+char *
+vfs_get_current_dir_n (void)
 {
     return g_strdup (current_path->str);
 }

+ 2 - 1
lib/vfs/vfs.h

@@ -232,7 +232,8 @@ void vfs_timeout_handler (void);
 int vfs_timeouts (void);
 void vfs_expire (gboolean now);
 
-char *vfs_get_current_dir (void);
+const char *vfs_get_current_dir (void);
+char *vfs_get_current_dir_n (void);
 const vfs_path_t *vfs_get_raw_current_dir (void);
 void vfs_set_raw_current_dir (const vfs_path_t * vpath);
 

+ 1 - 2
src/filemanager/midnight.c

@@ -914,13 +914,12 @@ done_mc (void)
      * We sync the profiles since the hotlist may have changed, while
      * we only change the setup data if we have the auto save feature set
      */
-    char *curr_dir;
+    const char *curr_dir;
 
     save_setup (auto_save_setup, panels_options.auto_save_setup);
 
     curr_dir = vfs_get_current_dir ();
     vfs_stamp_path (curr_dir);
-    g_free (curr_dir);
 
     if ((current_panel != NULL) && (get_current_type () == view_listing))
         vfs_stamp_path (vfs_path_as_str (current_panel->cwd_vpath));

+ 3 - 5
src/filemanager/usermenu.c

@@ -792,18 +792,16 @@ expand_format (struct WEdit *edit_widget, char c, gboolean do_quote)
         goto ret;
     case 'd':
         {
-            char *cwd;
+            const char *cwd;
             char *qstr;
 
-            if (panel)
-                cwd = g_strdup (vfs_path_as_str (panel->cwd_vpath));
+            if (panel != NULL)
+                cwd = vfs_path_as_str (panel->cwd_vpath);
             else
                 cwd = vfs_get_current_dir ();
 
             qstr = quote_func (cwd, FALSE);
 
-            g_free (cwd);
-
             result = qstr;
             goto ret;
         }