#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)

GameSetup.cpp#L600

Line 
593if (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;
 }

Change History (3)

comment:1 by Itms, 16 months ago

I think changing exit(0) to return false is absolutely correct.

Init returning false is going to cause Shutdown to be called with the SHUTDOWN_FROM_CONFIG flag, which reduces the shutdown sequence to everything inited before the config system. In Init, 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 why return false was not used. But return false is, with the current code, the correct way to end the dumpSchema sequence.

comment:2 by Itms, 16 months ago

Patch: Phab:D4903

comment:3 by Itms, 16 months ago

Resolution: fixed
Status: assignedclosed

In 27470:

Follow proper Shutdown sequence when using -dumpSchema, fixes #6696.

Also fix an incorrect code comment, and prevent Atlas from being started with -dumpSchema.

Reviewed By: phosit
Differential Revision: https://code.wildfiregames.com/D4903

Note: See TracTickets for help on using tickets.