From 948f98cf4a083e9c9c034fb3cbbb532debe5ceb8 Mon Sep 17 00:00:00 2001
From: Isaac Nickaein <nickaein.i@gmail.com>
Date: Tue, 12 Nov 2019 22:24:11 +0330
Subject: [PATCH] Cleanups

Make our intent more clear in destruction
---
 include/nlohmann/json.hpp        | 5 ++++-
 single_include/nlohmann/json.hpp | 5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp
index b60122cc..5a66a860 100644
--- a/include/nlohmann/json.hpp
+++ b/include/nlohmann/json.hpp
@@ -1035,9 +1035,12 @@ class basic_json
                     {
                         stack.push_back(std::move(it.second));
                     }
+
+                    current_item.m_value.object->clear();
                 }
 
-                // current_item is destroyed here
+                // it's now safe that current_item get destructed
+                // since it doesn't have any children
             }
 
             switch (t)
diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp
index d2d85b3d..8acb1cc0 100644
--- a/single_include/nlohmann/json.hpp
+++ b/single_include/nlohmann/json.hpp
@@ -15578,9 +15578,12 @@ class basic_json
                     {
                         stack.push_back(std::move(it.second));
                     }
+
+                    current_item.m_value.object->clear();
                 }
 
-                // current_item is destroyed here
+                // it's now safe that current_item get destructed
+                // since it doesn't have any children
             }
 
             switch (t)