Added FPDFPageObj_Destroy() for freeing page objects created
Bug=pdfium:854
Change-Id: I227418cdcb77e0aa7d48338f1ee0d753cef6bfdb
Reviewed-on: https://pdfium-review.googlesource.com/10390
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Jane Liu <janeliulwq@google.com>
diff --git a/fpdfsdk/fpdfedit_embeddertest.cpp b/fpdfsdk/fpdfedit_embeddertest.cpp
index f1bbb87..c381b25 100644
--- a/fpdfsdk/fpdfedit_embeddertest.cpp
+++ b/fpdfsdk/fpdfedit_embeddertest.cpp
@@ -1030,3 +1030,11 @@
UnloadPage(page);
}
+
+TEST_F(FPDFEditEmbeddertest, DestroyPageObject) {
+ FPDF_PAGEOBJECT rect = FPDFPageObj_CreateNewRect(10, 10, 20, 20);
+ ASSERT_TRUE(rect);
+
+ // There should be no memory leaks with a call to FPDFPageObj_Destroy().
+ FPDFPageObj_Destroy(rect);
+}
diff --git a/fpdfsdk/fpdfeditpage.cpp b/fpdfsdk/fpdfeditpage.cpp
index a7ee212..91b966c 100644
--- a/fpdfsdk/fpdfeditpage.cpp
+++ b/fpdfsdk/fpdfeditpage.cpp
@@ -201,6 +201,10 @@
return pPage && pPage->BackgroundAlphaNeeded();
}
+DLLEXPORT void STDCALL FPDFPageObj_Destroy(FPDF_PAGEOBJECT page_obj) {
+ delete CPDFPageObjectFromFPDFPageObject(page_obj);
+}
+
DLLEXPORT FPDF_BOOL STDCALL
FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) {
if (!pageObject)
diff --git a/fpdfsdk/fpdfview_c_api_test.c b/fpdfsdk/fpdfview_c_api_test.c
index d40437c..ef5b804 100644
--- a/fpdfsdk/fpdfview_c_api_test.c
+++ b/fpdfsdk/fpdfview_c_api_test.c
@@ -121,6 +121,7 @@
CHK(FPDFPage_GetObject);
CHK(FPDFPage_HasTransparency);
CHK(FPDFPage_GenerateContent);
+ CHK(FPDFPageObj_Destroy);
CHK(FPDFPageObj_HasTransparency);
CHK(FPDFPageObj_GetBounds);
CHK(FPDFPageObj_GetType);
diff --git a/public/fpdf_edit.h b/public/fpdf_edit.h
index dc710b5..aab48af 100644
--- a/public/fpdf_edit.h
+++ b/public/fpdf_edit.h
@@ -141,6 +141,15 @@
// |FPDFPage_GenerateContent| or any changes to |page| will be lost.
DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page);
+// Destroy |page_obj| by releasing its resources. |page_obj| must have been
+// created by FPDFPageObj_CreateNew{Path|Rect}() or
+// FPDFPageObj_New{Text|Image}Obj(). This function must be called on
+// newly-created objects if they are not added to a page through
+// FPDFPage_InsertObject() or to an annotation through FPDFAnnot_AppendObject().
+//
+// page_obj - handle to a page object.
+DLLEXPORT void STDCALL FPDFPageObj_Destroy(FPDF_PAGEOBJECT page_obj);
+
// Checks if |page_object| contains transparency.
//
// page_object - handle to a page object.