Pelles C > Bug reports

Problem with spawn a process

(1/2) > >>

Jens:
Compile and link this example with 32bit, all is ok.
But with 64bit i must close the open logfile before call _spawn or execution crashes.



--- Code: ---// ***********************************************************************

#include <stdio.h>
#include <stdlib.h>
#include <process.h>

// ***************************** Code Start *********************************

int main(int argc, char **argv)
{
FILE *log=NULL;
long long notep_pid=0;
int rc=0;
char *user_file="C:\\Temp\\T\\T.txt\0", *log_file="C:\\Temp\\T\\T.log\0";

log=fopen(log_file, "w+");
if(log) fprintf(log, "\n    Log File is open");

//fclose(log);

notep_pid=_cwait (&rc, _spawnl(_P_NOWAIT, "C:\\Windows\\notepad.exe\0", "notepad.exe\0", user_file, 0), 0);

//log=fopen(log_file, "a");

fprintf(stdout, "\n    STATUS %d, SPID %lld", rc, notep_pid);
fprintf(stdout, "\n");
fclose(log);

return rc;
}

// **************************** Code End *****************************

--- End code ---

TimoVJL:
optimization problem with const?

Jens:
ok,

that's the reason.
I compile without the -OT option and everything is fine.

THANKS Jens :) :)

Jens:
Hi again,

sorry, but my problem isn't solved.

First Example (see above) was running well.
But because it wasn't that what I want, I do some other tests
and the result was always the same. Program chrashed at end of execution.

If you test the code an uncomment "#define TEST" the prog crashed

example code:


--- Code: ---// *************************************************************************

//#define TEST

// *************************************************************************

#include <stdio.h>
#include <stdlib.h>
#include <process.h>

// *************************************************************************

FILE *log=NULL;

// ***************************** Code Start *********************************

int TestSpawn(const char *ufile)
{
long long notepad_id=0;
int rc=0;

notepad_id=_cwait (&rc, _spawnl(_P_NOWAIT, "C:\\Windows\\notepad.exe\0", "notepad.exe\0", ufile, 0), 0);
fprintf(log, "\n    STATUS %d, NPAD_ID %lld\n", rc, notepad_id);

return rc;
}

// *************************************************************************

int main(int argc, char **argv)
{
FILE *test=NULL;
int rc=0;
const char *log_file="D:\\Temp\\T\\T.log\0", *user_file="D:\\Temp\\T\\T1.txt\0", *test_file="D:\\Temp\\T\\T2.txt\0";
log=fopen(log_file, "w+");
if(!log)
{
perror("\n  No Log File ");
exit(EXIT_FAILURE);
}
fprintf(log, "\n    Log File is open\n");

rc=TestSpawn(user_file);

#ifdef TEST

test=fopen(test_file, "w");
if(!test)
{
perror("\n  No Test File ");
exit(EXIT_FAILURE);
}
if(test) fprintf(test, "\n    Test File is open");
fprintf(test, "\n    STATUS %d\n", rc);
fprintf(test, "\n    Test File closed\n\n    END\n");
fflush(test);
fclose(test);

#endif

fprintf(log, "\n    STATUS %d\n", rc);
fprintf(log, "\n    Log File closed\n\n    END\n");
fflush(log);
fclose(log);
fprintf(stdout, "\n    END STATUS %d\n", rc);
fprintf(stdout, "    END\n");

return EXIT_SUCCESS;
}

// **************************** Code End *****************************

--- End code ---

compiler flags: -std:C11 -Tx64-coff -Zi -Ob0 -fp:precise -W1 -Gr -J

linker flags: -subsystem:console -machine:x64 -LIBPATH:C:\PellesC\Lib\Win64 kernel32.lib user32.lib advapi32.lib delayimp64.lib

error message:
CRT: unhandled exception (main) -- terminating
*** Process returned 255 ***
Press any key to continue...

debug: Access violation --->>> fclose(file)

Tested with 3 PCs
Win7- intel i3, Win8.1- intel i5, Win10-intel i7

If this is not the right sub-forum, feel free to move it.
regards and thanks

Jens

frankie:
The fault is generated in the fclose function due to malloced memory header corruption.
Maybe there is a bug in the spawn functions in 64bits compilation.
I'll check better as soon I have enough time.

Navigation

[0] Message Index

[#] Next page

Go to full version