This patch is fixing a possible memory corruption and abnormal exit
of wmaker when a created child process errored.
This had been kind of mentioned at
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1040643and I also experienced it with especially Steam.
At first, I also thought it was a crash or a memory corruption,
but gdb or valgrind are not reporting anything.
In fact, Steam is not setting properly some hints and that is bringing
some issues. More patches will be needed to support that app properly.
For example, WM_COMMAND is not set properly and when you are trying to
relaunch the app from the appIcon the child process is generating an error
and the actual code is calling Exit(-1) which is entirely exiting wmaker,
that's why from gdb you can see the message
[Inferior 4 (process 567278) exited normally] and no crash.
---
src/main.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/src/main.c b/src/main.c
index 7bc8bcdb..e382a7be 100644
--- a/src/main.c
+++ b/src/main.c
@@ -326,7 +326,8 @@ void ExecuteShellCommand(WScreen *scr, const char *command)
#endif
execl(shell, shell, "-c", command, NULL);
werror("could not execute %s -c %s", shell, command);
-
Exit(-1);
+
/* exec failed in child -- exit immediately without running parent cleanup */
+
_exit(127);
} else if (pid < 0) {
werror("cannot fork a new process");
} else {
@@ -377,10 +378,10 @@ Bool RelaunchWindow(WWindow *wwin)
setsid();
#endif
/* argv is not null-terminated */
-
char **a = (char **) malloc(argc + 1);
+
char **a = malloc((argc + 1) * sizeof(char *));
if (! a) {
werror("out of memory trying to relaunch the application");
-
Exit(-1);
+
_exit(127);
}
int i;
@@ -389,7 +390,8 @@ Bool RelaunchWindow(WWindow *wwin)
a[i] = NULL;
execvp(a[0], a);
-
Exit(-1);
+
/* exec failed in child -- exit immediately */
+
_exit(127);
} else if (pid < 0) {
werror("cannot fork a new process");
--
2.43.0