Use wxFFileInputStream to avoid dangling pointer
Cases where fp was left open could lead to dangling files until KiCad is closed. Stack-based file stream automatically closes after parsing and on exception Fixes https://gitlab.com/kicad/code/kicad/issues/9336
This commit is contained in:
parent
677166f0b8
commit
3c29e68992
|
@ -35,6 +35,7 @@
|
|||
#include <wx/fileconf.h>
|
||||
#include <wx/filename.h>
|
||||
#include <wx/log.h>
|
||||
#include <wx/stdstream.h>
|
||||
#include <wx/wfstream.h>
|
||||
|
||||
const wxChar* const traceSettings = wxT( "KICAD_SETTINGS" );
|
||||
|
@ -262,12 +263,13 @@ bool JSON_SETTINGS::LoadFromFile( const wxString& aDirectory )
|
|||
|
||||
try
|
||||
{
|
||||
FILE* fp = wxFopen( path.GetFullPath(), wxT( "rt" ) );
|
||||
wxFFileInputStream fp( path.GetFullPath(), wxT( "rt" ) );
|
||||
wxStdInputStream fstream( fp );
|
||||
|
||||
if( fp )
|
||||
if( fp.IsOk() )
|
||||
{
|
||||
*static_cast<nlohmann::json*>( m_internals.get() ) =
|
||||
nlohmann::json::parse( fp, nullptr,
|
||||
nlohmann::json::parse( fstream, nullptr,
|
||||
/* allow_exceptions = */ true,
|
||||
/* ignore_comments = */ true );
|
||||
|
||||
|
|
Loading…
Reference in New Issue