]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/cmdlib/cmdlib.cpp
radiant: replace StringBuffer with std::string
[xonotic/netradiant.git] / libs / cmdlib / cmdlib.cpp
index 9bfd24364dc4bff37e09a5354b10f3070cf7d364..25c5d9addeae227c569410633909a04fb700f12f 100644 (file)
@@ -40,7 +40,7 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 
-bool Q_Exec( const char *cmd, char *cmdline, const char *, bool, bool waitfor ){
+bool Q_Exec( const char *cmd, const char *cmdline, const char *, bool, bool waitfor ){
        char fullcmd[2048];
        char *pCmd;
        pid_t pid;
@@ -91,7 +91,7 @@ bool Q_Exec( const char *cmd, char *cmdline, const char *, bool, bool waitfor ){
 #include <windows.h>
 
 // NOTE TTimo windows is VERY nitpicky about the syntax in CreateProcess
-bool Q_Exec( const char *cmd, char *cmdline, const char *execdir, bool bCreateConsole, bool waitfor ){
+bool Q_Exec( const char *cmd, const char *cmdline, const char *execdir, bool bCreateConsole, bool waitfor ){
        PROCESS_INFORMATION ProcessInformation;
        STARTUPINFO startupinfo = {0};
        DWORD dwCreationFlags;
@@ -102,14 +102,12 @@ bool Q_Exec( const char *cmd, char *cmdline, const char *execdir, bool bCreateCo
        else{
                dwCreationFlags = DETACHED_PROCESS | NORMAL_PRIORITY_CLASS;
        }
-       const char *pCmd;
-       char *pCmdline;
-       pCmd = cmd;
+       const char *pCmd = cmd;
        if ( pCmd ) {
                while ( *pCmd == ' ' )
                        pCmd++;
        }
-       pCmdline = cmdline;
+       char *pCmdline = strdup(cmdline);
        if ( pCmdline ) {
                while ( *pCmdline == ' ' )
                        pCmdline++;
@@ -130,8 +128,10 @@ bool Q_Exec( const char *cmd, char *cmdline, const char *execdir, bool bCreateCo
                if ( waitfor ) {
                        WaitForSingleObject( ProcessInformation.hProcess, INFINITE );
                }
+               free(pCmdline);
                return true;
        }
+       free(pCmdline);
        return false;
 }