* view.c (do_view_init): Make sure _file is not

an empty string before mc_stat and mc_open.
Memory leak fixed.
This commit is contained in:
Pavel Roskin 2001-11-14 20:15:36 +00:00
parent 79dd5b30cb
commit e50abb3f80
2 changed files with 32 additions and 26 deletions

View File

@ -1,3 +1,9 @@
2001-11-14 Andrew V. Samoilov <kai@cmail.ru>
* view.c (do_view_init): Make sure _file is not
an empty string before mc_stat and mc_open.
Memory leak fixed.
2001-11-14 Pavel Roskin <proski@gnu.org>
* panelize.c (do_external_panelize): Re-sort the panel according

View File

@ -508,7 +508,7 @@ do_view_init (WView *view, char *_command, const char *_file, int start_line)
{
char *error = 0;
int i, type;
int fd;
int fd = -1;
char tmp[BUF_MEDIUM];
if (view->view_active)
@ -539,34 +539,34 @@ do_view_init (WView *view, char *_command, const char *_file, int start_line)
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'))