Filtered view (M!) works again



Hi, Pavel!

This patch makes "Filtered view" (M-!) feature work again
and fixes memory leak.  It was broken recently with file
type checks.

P.S. Some days ago I mailed --enable-largefile vs smbfs
is fixed.  It is not so.
sizeof (off_t) == 8 in MC but 4 in samba.  

ChangeLog:

	* view.c (do_view_init): Make sure _file is not 
	an empty string before mc_stat and mc_open.
	Memory 	leak fixed.

--- view.c-orig	Thu Nov  8 09:36:43 2001
+++ view.c	Thu Nov  8 10:23:01 2001
@@ -539,34 +539,34 @@ do_view_init (WView *view, char *_comman
 	view->start_col = 0;
     }
 
-    /* Make sure we are working with a regular file */
-    if (mc_stat (view->filename, &view->s) == -1) {
-	g_snprintf (tmp, sizeof (tmp), _(" Cannot stat \"%s\"\n %s "),
-		    _file, unix_error_string (errno));
-	error = set_view_init_error (view, tmp);
-	goto finish;
-    }
+    if (_file[0]) {
+	/* Make sure we are working with a regular file */
+	if (mc_stat (view->filename, &view->s) == -1) {
+	    g_snprintf (tmp, sizeof (tmp), _(" Cannot stat \"%s\"\n %s "),
+			_file, unix_error_string (errno));
+	    error = set_view_init_error (view, tmp);
+	    goto finish;
+	}
 
-    if (!S_ISREG (view->s.st_mode)) {
-	g_snprintf (tmp, sizeof (tmp),
-		    _(" Cannot view: not a regular file "));
-	error = set_view_init_error (view, tmp);
-	goto finish;
-    }
+	if (!S_ISREG (view->s.st_mode)) {
+	    g_snprintf (tmp, sizeof (tmp),
+			_(" Cannot view: not a regular file "));
+	    error = set_view_init_error (view, tmp);
+	    goto finish;
+	}
 
-    /* Actually open the file */
-    if ((fd = mc_open(_file, O_RDONLY)) == -1) {
-	g_snprintf (tmp, sizeof (tmp), _(" Cannot open \"%s\"\n %s "),
-		    _file, unix_error_string (errno));
-	error = set_view_init_error (view, tmp);
-	goto finish;
-    }
+	/* Actually open the file */
+	if ((fd = mc_open(_file, O_RDONLY)) == -1) {
+	    g_snprintf (tmp, sizeof (tmp), _(" Cannot open \"%s\"\n %s "),
+			_file, unix_error_string (errno));
+	    error = set_view_init_error (view, tmp);
+	    goto finish;
+	}
 
-    if (_file[0] && view->viewer_magic_flag && (is_gunzipable (fd, &type)) != 0) {
-	g_free (view->filename);
-	view->filename = g_strconcat (_file, decompress_extension(type), NULL);
-    } else {
-	view->filename = g_strdup (_file);
+	if (view->viewer_magic_flag && (is_gunzipable (fd, &type)) != 0) {
+	    g_free (view->filename);
+	    view->filename = g_strconcat (_file, decompress_extension(type), NULL);
+	}
     }
 
     if (_command && (view->viewer_magic_flag || _file[0] == '\0'))



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]