From 8e93c19de311a76704028b0195abfe04cfad900d Mon Sep 17 00:00:00 2001
From: Pierre-Emmanuel Viel
Date: Thu, 26 Dec 2013 23:04:54 +0100
Subject: [PATCH] Fix a heap issue with static on Windows
---
.../flann/include/opencv2/flann/lsh_table.h | 20 ++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/modules/flann/include/opencv2/flann/lsh_table.h b/modules/flann/include/opencv2/flann/lsh_table.h
index 6b8d614f23..18fb139c91 100644
--- a/modules/flann/include/opencv2/flann/lsh_table.h
+++ b/modules/flann/include/opencv2/flann/lsh_table.h
@@ -348,21 +348,27 @@ inline LshTable::LshTable(unsigned int feature_size, unsigned int
mask_ = std::vector((size_t)ceil((float)(feature_size * sizeof(char)) / (float)sizeof(size_t)), 0);
// A bit brutal but fast to code
- static std::vector indices(feature_size * CHAR_BIT);
+ static std::vector* indices = NULL;
//Ensure the Nth bit will be selected only once among the different LshTables
//to avoid having two different tables with signatures sharing many dimensions/many bits
- if( (indices.size() == feature_size * CHAR_BIT) || (indices.size() < key_size_) )
+ if( indices == NULL )
{
- indices.resize( feature_size * CHAR_BIT );
- for (size_t i = 0; i < feature_size * CHAR_BIT; ++i) indices[i] = i;
- std::random_shuffle(indices.begin(), indices.end());
+ indices = new std::vector( feature_size * CHAR_BIT );
+ }
+ else if( indices->size() < key_size_ )
+ {
+ indices->resize( feature_size * CHAR_BIT );
+ for (size_t i = 0; i < feature_size * CHAR_BIT; ++i) {
+ (*indices)[i] = i;
+ }
+ std::random_shuffle(indices->begin(), indices->end());
}
// Generate a random set of order of subsignature_size_ bits
for (unsigned int i = 0; i < key_size_; ++i) {
- size_t index = indices[0];
- indices.erase( indices.begin() );
+ size_t index = (*indices)[0];
+ indices->erase( indices->begin() );
// Set that bit in the mask
size_t divisor = CHAR_BIT * sizeof(size_t);