From af30d8fc59186963c309a1c91190543e1d00dc0c Mon Sep 17 00:00:00 2001
From: Mooffie <mooffie@gmail.com>
Date: Mon, 14 Dec 2015 23:06:07 +0200
Subject: [PATCH] Invalid command-line options cause segfault.
That's because main() calls mc_shell_deinit() without mc_shell_init()
having been called.
Solution: we make mc_shell_deinit() not crash when mc_global.shell ==
NULL.
(The use of MC_PTR_FREE there is just a matter of style -- it's not part
of the solution.)
The patch also moves the call to mc_shell_deinit() past
'startup_exit_ok:'. This is obviously the intended design.
'startup_exit_falure:' is just meant to print mcerror.
---
lib/shell.c | 7 +++++--
src/main.c | 3 +--
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/lib/shell.c b/lib/shell.c
index 5159909..3d9ba2e 100644
a
|
b
|
mc_shell_init (void) |
243 | 243 | void |
244 | 244 | mc_shell_deinit (void) |
245 | 245 | { |
246 | | g_free (mc_global.shell->path); |
247 | | g_free (mc_global.shell); |
| 246 | if (mc_global.shell != NULL) |
| 247 | { |
| 248 | g_free (mc_global.shell->path); |
| 249 | MC_PTR_FREE (mc_global.shell); |
| 250 | } |
248 | 251 | } |
249 | 252 | |
250 | 253 | /* --------------------------------------------------------------------------------------------- */ |
diff --git a/src/main.c b/src/main.c
index aec94c4..4e6503c 100644
a
|
b
|
main (int argc, char *argv[]) |
244 | 244 | startup_exit_falure: |
245 | 245 | fprintf (stderr, _("Failed to run:\n%s\n"), mcerror->message); |
246 | 246 | g_error_free (mcerror); |
247 | | |
248 | | mc_shell_deinit (); |
249 | 247 | startup_exit_ok: |
| 248 | mc_shell_deinit (); |
250 | 249 | str_uninit_strings (); |
251 | 250 | mc_timer_destroy (mc_global.timer); |
252 | 251 | return exit_code; |