Skip to content

Commit 2c32cb7

Browse files
committed
Merge pull request opencv#18016 from pemmanuelviel:pev--cleaner-hierarchical-clustering
2 parents 883b995 + bc221bd commit 2c32cb7

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

modules/flann/include/opencv2/flann/hierarchical_clustering_index.h

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -404,34 +404,16 @@ class HierarchicalClusteringIndex : public NNIndex<Distance>
404404
*/
405405
virtual ~HierarchicalClusteringIndex()
406406
{
407-
free_elements();
408-
409407
if (root!=NULL) {
410408
delete[] root;
411409
}
412410

413411
if (indices!=NULL) {
412+
free_indices();
414413
delete[] indices;
415414
}
416415
}
417416

418-
419-
/**
420-
* Release the inner elements of indices[]
421-
*/
422-
void free_elements()
423-
{
424-
if (indices!=NULL) {
425-
for(int i=0; i<trees_; ++i) {
426-
if (indices[i]!=NULL) {
427-
delete[] indices[i];
428-
indices[i] = NULL;
429-
}
430-
}
431-
}
432-
}
433-
434-
435417
/**
436418
* Returns size of index.
437419
*/
@@ -467,7 +449,7 @@ class HierarchicalClusteringIndex : public NNIndex<Distance>
467449
throw FLANNException("Branching factor must be at least 2");
468450
}
469451

470-
free_elements();
452+
free_indices();
471453

472454
for (int i=0; i<trees_; ++i) {
473455
indices[i] = new int[size_];
@@ -503,13 +485,12 @@ class HierarchicalClusteringIndex : public NNIndex<Distance>
503485

504486
void loadIndex(FILE* stream) CV_OVERRIDE
505487
{
506-
free_elements();
507-
508488
if (root!=NULL) {
509489
delete[] root;
510490
}
511491

512492
if (indices!=NULL) {
493+
free_indices();
513494
delete[] indices;
514495
}
515496

@@ -649,6 +630,20 @@ class HierarchicalClusteringIndex : public NNIndex<Distance>
649630
}
650631

651632

633+
/**
634+
* Release the inner elements of indices[]
635+
*/
636+
void free_indices()
637+
{
638+
if (indices!=NULL) {
639+
for(int i=0; i<trees_; ++i) {
640+
if (indices[i]!=NULL) {
641+
delete[] indices[i];
642+
indices[i] = NULL;
643+
}
644+
}
645+
}
646+
}
652647

653648

654649
void computeLabels(int* dsindices, int indices_length, int* centers, int centers_length, int* labels, DistanceType& cost)

0 commit comments

Comments
 (0)