Skip to content

Commit

Permalink
valgrind out a few memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
liuliu committed Jun 30, 2012
1 parent 284dc06 commit 1887316
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/ccv_swt.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ static ccv_array_t* _ccv_swt_merge_textline(ccv_array_t* letters, ccv_swt_param_
_ccv_swt_add_letter(chain + j,((ccv_letter_pair_t*)ccv_array_get(pairs, i))->left);
_ccv_swt_add_letter(chain + j, ((ccv_letter_pair_t*)ccv_array_get(pairs, i))->right);
}
ccv_array_free(idx);
ccv_array_free(pairs);
ccv_array_t* regions = ccv_array_new(5, sizeof(ccv_textline_t));
for (i = 0; i < nchains; i++)
Expand Down Expand Up @@ -559,6 +560,8 @@ static ccv_array_t* _ccv_swt_break_words(ccv_array_t* textline, ccv_swt_param_t
}
if (nt.neighbors >= params.letter_thresh && nt.rect.width > nt.rect.height * params.elongate_ratio)
ccv_array_push(words, &nt.rect);
if (nt.letters)
ccfree(nt.letters);
} else {
ccv_array_push(words, &(t->rect));
}
Expand Down Expand Up @@ -610,9 +613,11 @@ ccv_array_t* ccv_swt_detect_words(ccv_dense_matrix_t* a, ccv_swt_param_t params)
ccv_textline_t* r2 = (ccv_textline_t*)ccv_array_get(textline2, k);
if (r2->rect.width < r->rect.width)
{
if (r2->letters != 0)
if (r2->letters)
ccfree(r2->letters);
*r2 = *r;
} else if (r->letters) {
ccfree(r->letters);
}
}
ccv_array_free(idx);
Expand All @@ -632,7 +637,8 @@ ccv_array_t* ccv_swt_detect_words(ccv_dense_matrix_t* a, ccv_swt_param_t params)
for (i = 0; i < textline->rnum; i++)
{
ccv_textline_t* r = (ccv_textline_t*)ccv_array_get(textline, i);
ccfree(r->letters);
if (r->letters)
ccfree(r->letters);
int k = *(int*)ccv_array_get(idx, i);
ccv_rect_t* r2 = (ccv_rect_t*)ccv_array_get(words, k);
if (r2->width * r2->height < r->rect.width * r->rect.height)
Expand Down
2 changes: 2 additions & 0 deletions test/functional/util.tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,11 @@ TEST_CASE("matrix flatten")
dmt->data.u8[7] = 250;
ccv_dense_matrix_t* result = 0;
ccv_flatten(dmt, (ccv_matrix_t**)&result, 0, 0);
ccv_matrix_free(dmt);
int rf[4] = {300, 200, 45, 450};
REQUIRE_EQ(CCV_GET_CHANNEL(result->type), CCV_C1, "flatten matrix should has only one channel");
REQUIRE_ARRAY_EQ(int, result->data.i32, rf, 4, "matrix flatten should has same value as reference array");
ccv_matrix_free(result);
}

#include "case_main.h"

0 comments on commit 1887316

Please sign in to comment.