diff --git a/src/DynareMain2.cc b/src/DynareMain2.cc
index f12e63246a43b5eae6842bef3f1428a4d4f15e20..9933f31187a118e95fa200c501b573517d47bd0c 100644
--- a/src/DynareMain2.cc
+++ b/src/DynareMain2.cc
@@ -45,7 +45,7 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear
   boost::filesystem::remove_all(basename + "/model/json");
 
   // Do parsing and construct internal representation of mod file
-  ModFile *mod_file = p.parse(in, debug);
+  unique_ptr<ModFile> mod_file = p.parse(in, debug);
   if (json == JsonOutputPointType::parsing)
     mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson, nopreprocessoroutput);
 
@@ -79,8 +79,6 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear
                                , nopreprocessoroutput
                                );
 
-  delete mod_file;
-
   if (!nopreprocessoroutput)
     cout << "Preprocessing completed." << endl;
 }
diff --git a/src/ParsingDriver.cc b/src/ParsingDriver.cc
index 908b8e28255e767857bc2e936ab6e86bbd7e81c7..65b9b62cdc589ca45a38df922ee82c0686fbebad 100644
--- a/src/ParsingDriver.cc
+++ b/src/ParsingDriver.cc
@@ -86,10 +86,10 @@ ParsingDriver::reset_current_external_function_options()
   current_external_function_id = eExtFunNotSet;
 }
 
-ModFile *
+unique_ptr<ModFile>
 ParsingDriver::parse(istream &in, bool debug)
 {
-  mod_file = new ModFile(warnings);
+  mod_file = make_unique<ModFile>(warnings);
 
   symbol_list.clear();
 
@@ -98,16 +98,14 @@ ParsingDriver::parse(istream &in, bool debug)
   osr_params.init(*data_tree);
   reset_current_external_function_options();
 
-  lexer = new DynareFlex(&in);
+  lexer = make_unique<DynareFlex>(&in);
   lexer->set_debug(debug);
 
   Dynare::parser parser(*this);
   parser.set_debug_level(debug);
   parser.parse();
 
-  delete lexer;
-
-  return mod_file;
+  return move(mod_file);
 }
 
 void
@@ -357,11 +355,10 @@ ParsingDriver::declare_or_change_type(SymbolType new_type, const string &name)
       mod_file->symbol_table.changeType(symb_id, new_type);
 
       // change in equations in ModelTree
-      auto *dm = new DynamicModel(mod_file->symbol_table,
+      auto dm = make_unique<DynamicModel>(mod_file->symbol_table,
                                           mod_file->num_constants,
                                           mod_file->external_functions_table);
       mod_file->dynamic_model.updateAfterVariableChange(*dm);
-      delete dm;
 
       // remove error messages
       undeclared_model_vars.erase(name);
diff --git a/src/ParsingDriver.hh b/src/ParsingDriver.hh
index 8a4ebb30de4c73e7614957c4ca1cdaacae1a6ca3..0c51e7c1cc9d5fe4fbeeeb8aff3bd15f80c05bd1 100644
--- a/src/ParsingDriver.hh
+++ b/src/ParsingDriver.hh
@@ -241,7 +241,7 @@ private:
   map<string, vector<string>> var_map;
 
   //! The mod file representation constructed by this ParsingDriver
-  ModFile *mod_file;
+  unique_ptr<ModFile> mod_file;
 
   WarningConsolidation &warnings;
 
@@ -257,11 +257,10 @@ public:
   ParsingDriver(WarningConsolidation &warnings_arg, bool nostrict_arg) : warnings(warnings_arg), nostrict(nostrict_arg) { };
 
   //! Starts parsing, and constructs the MOD file representation
-  /*! The returned pointer should be deleted after use */
-  ModFile *parse(istream &in, bool debug);
+  unique_ptr<ModFile> parse(istream &in, bool debug);
 
   //! Reference to the lexer
-  class DynareFlex *lexer;
+  unique_ptr<DynareFlex> lexer;
 
   //! Copy of parsing location, maintained by YYLLOC_DEFAULT macro in DynareBison.yy
   Dynare::parser::location_type location;