From 80bf582f00adeefae67ae432b74c3b0609e7845e Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 13 Feb 2018 20:55:03 +0000 Subject: Cleanup CXFA_Node ownership Currently a CXFA_Node can be owned by the CXFA_Document root pointer, the CXFA_Document Purge list or as a child of another CXFA_Node. This makes it hard to know who currently owns what. This CL moves all ownership of nodes into a CXFA_NodeOwner class which CXFA_Document subclasses. The node owner always owns all nodes and is responsible for cleaning them up upon destruction. The destruction order is not guarenteed to be in tree order as nodes can be inserted and moved around the tree. Change-Id: I6b202b8e844999ba835093dcdd1a808938b6d9a8 Reviewed-on: https://pdfium-review.googlesource.com/26434 Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- xfa/fxfa/parser/cxfa_nodeowner.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 xfa/fxfa/parser/cxfa_nodeowner.cpp (limited to 'xfa/fxfa/parser/cxfa_nodeowner.cpp') diff --git a/xfa/fxfa/parser/cxfa_nodeowner.cpp b/xfa/fxfa/parser/cxfa_nodeowner.cpp new file mode 100644 index 0000000000..ae6f589616 --- /dev/null +++ b/xfa/fxfa/parser/cxfa_nodeowner.cpp @@ -0,0 +1,35 @@ +// Copyright 2018 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/parser/cxfa_nodeowner.h" + +#include + +#include "third_party/base/stl_util.h" +#include "xfa/fxfa/parser/cxfa_node.h" + +CXFA_NodeOwner::CXFA_NodeOwner() = default; + +CXFA_NodeOwner::~CXFA_NodeOwner() = default; + +CXFA_Node* CXFA_NodeOwner::AddOwnedNode(std::unique_ptr node) { + if (!node) + return nullptr; + + CXFA_Node* ret = node.get(); + nodes_.insert(std::move(node)); + return ret; +} + +void CXFA_NodeOwner::FreeOwnedNode(CXFA_Node* node) { + if (!node) + return; + + pdfium::FakeUniquePtr search(node); + auto it = nodes_.find(search); + assert(it != nodes_.end()); + nodes_.erase(it); +} -- cgit v1.2.3