From 190584fec7018ed4b96c59260364df662ce0a837 Mon Sep 17 00:00:00 2001 From: Raf Schietekat Date: Wed, 10 May 2017 15:23:49 +0200 Subject: [PATCH] RAII: PB_LINE_IT::get_line(): was leaked inside POLY_BLOCK::fill() --- ccstruct/ocrblock.cpp | 11 +++++------ ccstruct/pdblock.cpp | 6 +++--- ccstruct/polyblk.cpp | 6 +++--- textord/scanedg.cpp | 8 ++++---- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/ccstruct/ocrblock.cpp b/ccstruct/ocrblock.cpp index ad7893b05a..19f2aecbfd 100644 --- a/ccstruct/ocrblock.cpp +++ b/ccstruct/ocrblock.cpp @@ -18,6 +18,7 @@ **********************************************************************/ #include +#include // std::unique_ptr #include "blckerr.h" #include "ocrblock.h" #include "stepblob.h" @@ -380,9 +381,8 @@ void BLOCK::compute_row_margins() { TBOX row_box = row->bounding_box(); int left_y = row->base_line(row_box.left()) + row->x_height(); int left_margin; - ICOORDELT_LIST *segments = lines.get_line(left_y); - LeftMargin(segments, row_box.left(), &left_margin); - delete segments; + const std::unique_ptr segments_left(lines.get_line(left_y)); + LeftMargin(segments_left.get(), row_box.left(), &left_margin); if (row_box.top() >= drop_cap_bottom) { int drop_cap_distance = row_box.left() - row->space() - drop_cap_right; @@ -394,9 +394,8 @@ void BLOCK::compute_row_margins() { int right_y = row->base_line(row_box.right()) + row->x_height(); int right_margin; - segments = lines.get_line(right_y); - RightMargin(segments, row_box.right(), &right_margin); - delete segments; + const std::unique_ptr segments_right(lines.get_line(right_y)); + RightMargin(segments_right.get(), row_box.right(), &right_margin); row->set_lmargin(left_margin); row->set_rmargin(right_margin); } diff --git a/ccstruct/pdblock.cpp b/ccstruct/pdblock.cpp index cf3289f2e7..4dde3988d0 100644 --- a/ccstruct/pdblock.cpp +++ b/ccstruct/pdblock.cpp @@ -18,6 +18,7 @@ **********************************************************************/ #include +#include // std::unique_ptr #include "allheaders.h" #include "blckerr.h" #include "pdblock.h" @@ -140,9 +141,9 @@ Pix* PDBLK::render_mask(const FCOORD& rerotation, TBOX* mask_box) { // rasterized interior. (Runs of interior pixels on a line.) PB_LINE_IT *lines = new PB_LINE_IT(&image_block); for (int y = box.bottom(); y < box.top(); ++y) { - ICOORDELT_LIST* segments = lines->get_line(y); + const std::unique_ptr segments(lines->get_line(y)); if (!segments->empty()) { - ICOORDELT_IT s_it(segments); + ICOORDELT_IT s_it(segments.get()); // Each element of segments is a start x and x size of the // run of interior pixels. for (s_it.mark_cycle_pt(); !s_it.cycled_list(); s_it.forward()) { @@ -154,7 +155,6 @@ Pix* PDBLK::render_mask(const FCOORD& rerotation, TBOX* mask_box) { xext, 1, PIX_SET, NULL, 0, 0); } } - delete segments; } delete lines; } else { diff --git a/ccstruct/polyblk.cpp b/ccstruct/polyblk.cpp index b5ca2e1212..bae881b1ff 100644 --- a/ccstruct/polyblk.cpp +++ b/ccstruct/polyblk.cpp @@ -20,6 +20,7 @@ #include #include #include +#include // std::unique_ptr #include "elst.h" #include "polyblk.h" @@ -273,7 +274,6 @@ void POLY_BLOCK::fill(ScrollView* window, ScrollView::Color colour) { inT16 y; inT16 width; PB_LINE_IT *lines; - ICOORDELT_LIST *segments; ICOORDELT_IT s_it; lines = new PB_LINE_IT (this); @@ -281,9 +281,9 @@ void POLY_BLOCK::fill(ScrollView* window, ScrollView::Color colour) { for (y = this->bounding_box ()->bottom (); y <= this->bounding_box ()->top (); y++) { - segments = lines->get_line (y); + const std::unique_ptr segments(lines->get_line (y)); if (!segments->empty ()) { - s_it.set_to_list (segments); + s_it.set_to_list (segments.get()); for (s_it.mark_cycle_pt (); !s_it.cycled_list (); s_it.forward ()) { // Note different use of ICOORDELT, x coord is x coord of pixel // at the start of line segment, y coord is length of line segment diff --git a/textord/scanedg.cpp b/textord/scanedg.cpp index 0430843619..89b7c31a7f 100644 --- a/textord/scanedg.cpp +++ b/textord/scanedg.cpp @@ -19,6 +19,8 @@ #include "scanedg.h" +#include // std::unique_ptr + #include "allheaders.h" #include "edgloop.h" @@ -93,7 +95,6 @@ void make_margins( //get a line inT16 y //line coord ) { PB_LINE_IT *lines; - ICOORDELT_LIST *segments; //bits of a line ICOORDELT_IT seg_it; inT32 start; //of segment inT16 xext; //of segment @@ -101,9 +102,9 @@ void make_margins( //get a line if (block->poly_block () != NULL) { lines = new PB_LINE_IT (block->poly_block ()); - segments = lines->get_line (y); + const std::unique_ptr segments(lines->get_line (y)); if (!segments->empty ()) { - seg_it.set_to_list (segments); + seg_it.set_to_list (segments.get()); seg_it.mark_cycle_pt (); start = seg_it.data ()->x (); xext = seg_it.data ()->y (); @@ -122,7 +123,6 @@ void make_margins( //get a line for (xindex = left; xindex < right; xindex++) pixels[xindex - left] = margin; } - delete segments; delete lines; } else {