Opened 16 months ago
Closed 16 months ago
#6696 closed defect (fixed)
DumpSchema command line option segfaults on Linux
Reported by: | Stan | Owned by: | Itms |
---|---|---|---|
Priority: | Must Have | Milestone: | Alpha 27 |
Component: | Core engine | Keywords: | |
Cc: | Patch: | Phab:D4903 |
Description
When running the following command on Linux (macOS and Windows seem unaffected):
$ pyrogenesis -mod=public -dumpSchema
The file is generated correctly but a segfault occurs.
TIMER| InitVfs: 11.0418 ms FILES| Main log written to '/home/builder/.config/0ad/logs/mainlog.html' FILES| Interesting log written to '/home/builder/.config/0ad/logs/interestinglog.html' TIMER| CONFIG_Init: 61.519 ms Generated entity.rng mozilla::detail::MutexImp::~MutexImpl: pthread_mutex_destroy failed: Device or resource busy Segmentation fault (core dumped)
Line | |
---|---|
593 | if (args.Has("dumpSchema")) |
594 | { |
595 | CSimulation2 sim(NULL, g_ScriptContext, NULL); |
596 | sim.LoadDefaultScripts(); |
597 | std::ofstream f("entity.rng", std::ios_base::out | std::ios_base::trunc); |
598 | f << sim.GenerateSchema(); |
599 | std::cout << "Generated entity.rng\n"; |
600 | exit(0); |
601 | } |
It seems that replacing exit(0)
by return false prevents the segfault
if (args.Has("dumpSchema")) { CSimulation2 sim(NULL, g_ScriptContext, NULL); sim.LoadDefaultScripts(); std::ofstream f("entity.rng", std::ios_base::out | std::ios_base::trunc); f << sim.GenerateSchema(); std::cout << "Generated entity.rng\n"; - exit(0); + return false; }
Note:
See TracTickets
for help on using tickets.
I think changing
exit(0)
toreturn false
is absolutely correct.Init
returningfalse
is going to causeShutdown
to be called with theSHUTDOWN_FROM_CONFIG
flag, which reduces the shutdown sequence to everything inited before the config system. InInit
, we see that the config was the last thing to be inited before the schema was generated. The simulation created in the block will be properly freed first when returning.exit(0)
is in the code since the introduction of the dumpSchema feature (r7452) and it is anterior to the refinements of the init/shutdown code, so that explains whyreturn false
was not used. Butreturn false
is, with the current code, the correct way to end the dumpSchema sequence.