Skip to content

Commit

Permalink
RAII: PB_LINE_IT::get_line(): was leaked inside POLY_BLOCK::fill()
Browse files Browse the repository at this point in the history
  • Loading branch information
rfschtkt committed May 11, 2017
1 parent 8aa0a2d commit 190584f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
11 changes: 5 additions & 6 deletions ccstruct/ocrblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
**********************************************************************/

#include <stdlib.h>
#include <memory> // std::unique_ptr
#include "blckerr.h"
#include "ocrblock.h"
#include "stepblob.h"
Expand Down Expand Up @@ -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</*non-const*/ ICOORDELT_LIST> 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;
Expand All @@ -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</*non-const*/ ICOORDELT_LIST> 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);
}
Expand Down
6 changes: 3 additions & 3 deletions ccstruct/pdblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
**********************************************************************/

#include <stdlib.h>
#include <memory> // std::unique_ptr
#include "allheaders.h"
#include "blckerr.h"
#include "pdblock.h"
Expand Down Expand Up @@ -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</*non-const*/ ICOORDELT_LIST> 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()) {
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions ccstruct/polyblk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <memory> // std::unique_ptr
#include "elst.h"
#include "polyblk.h"

Expand Down Expand Up @@ -273,17 +274,16 @@ 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);
window->Pen(colour);

for (y = this->bounding_box ()->bottom ();
y <= this->bounding_box ()->top (); y++) {
segments = lines->get_line (y);
const std::unique_ptr</*non-const*/ ICOORDELT_LIST> 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
Expand Down
8 changes: 4 additions & 4 deletions textord/scanedg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#include "scanedg.h"

#include <memory> // std::unique_ptr

#include "allheaders.h"
#include "edgloop.h"

Expand Down Expand Up @@ -93,17 +95,16 @@ 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
int xindex; //index to pixel

if (block->poly_block () != NULL) {
lines = new PB_LINE_IT (block->poly_block ());
segments = lines->get_line (y);
const std::unique_ptr</*non-const*/ ICOORDELT_LIST> 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 ();
Expand All @@ -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 {
Expand Down

0 comments on commit 190584f

Please sign in to comment.