Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8070131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:17:45+00:00 2026-06-05T13:17:45+00:00

I know there is already at least a dozen valgrind reports invalid read questions,

  • 0

I know there is already at least a dozen valgrind reports invalid read questions, but please bear with me cause I really don’t know how to help myself so I’m asking for yours.

I am writing a wrapper for OpenCV feature detection and feature description modules (I want to be able to implement my own feat detection / extraction at some point). Because of that, I can not operate directly on OpenCV datatypes.

So, when extracting descriptors from features, I store them as std::vector <std::vector <double> > instead of cv::Mat. I have this piece of code where I first calculate the descriptors and then convert them from one notation to another:

// private
void CVDescriptor::calculateDescriptors(std::vector <cv::KeyPoint> &feats){
    this->feats = &feats;
    this->descCalc->compute(*(this->image), feats, this->desc);
    this->calculated = true;  
}

// public
void CVDescriptor::calculateDescriptors
                         (std::vector< std::vector< double > >& desc,
                          std::vector< cv::KeyPoint >& feats){    

    if (!this->calculated)
        this->calculateDescriptors(feats);

    assert(this->calculated);

    const double *temp;
    desc.clear();
    desc.reserve(this->desc.rows);
    for (int i=0, szi = this->desc.rows; i < szi; ++i){
        temp = this->desc.ptr<double>(i);

        // this line is the problem
        desc.push_back(std::vector<double>(temp, temp+(this->desc.cols)));
        //  .
        // /|\
        //  |
    }

    assert(desc.size() == this->desc.rows);
    assert(desc[0].size() == this->desc.cols);
    return;
}

Here are the types of my member variables, and I’ve checked and written where I initialize them (just to avoid confusion):

std::vector <cv::KeyPoint> *feats
cv::Mat *image;
    // it is set just before calling calculateDescriptors(desc, feats)
cv::Mat desc;
bool calculated; // set in the only constructor

Here’s the OpenCV documentation for cv::DescriptorExtractor::compute. From what I can see, each calculated descriptor should be one row in cv::Mat, and should have as much components as the matrix has columns.


I’m suspecting memory leaks at some places in my code, so I’ve run it through Valgrind. The first thing it reports is Invalid read of size 1 on the line marked with a big arrow in my code excerpt. As far as I can see, it is reporting it only twice per call to CVDescriptor::calculateDescriptors(..), not in every iteration of the for loop.

Can anyone see anything obviously wrong with my copying code? Or has any other ideas how this might be happening?

I can provide additional information if needed, but I’ve tried to put all the relevant code here (as my project is pretty big). Thank you all in advance (and I’m sorry for the lengthy question)…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:17:46+00:00Added an answer on June 5, 2026 at 1:17 pm

    I added a printout of the starting and ending addresses of the memory block being copied in every iteration, and that revealed the problem. Excerpt from the printout:

    copied from 0xc0d5990 -- 0xc0d5d90
    copied from 0xc0d5b90 -- 0xc0d5f90
    copied from 0xc0d5d90 -- 0xc0d6190
    copied from 0xc0d5f90 -- 0xc0d6390
    copied from 0xc0d6190 -- 0xc0d6590
    

    In every iteration I was accidentally trying to copy two rows of the cv::Mat at once, because I was accessing it through double pointers, while the data stored was float.

    Declaring temp as a const float *temp; and changing the temp assignment in

    temp = this->desc.ptr<float>(i);
    

    does the trick.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there are already many questions like mine but I found no answer
Before voting to close, please read, I know that there are similar questions (:
I know, there are a lot of questions about prime numbers already, but I
I know there are already objects supporting Office 2007 files, but is there any
First of all: I do know that there are already many questions and answers
I know there are a few questions on stack already regarding this, and I
First of, I know there are similar questions already on stackoverflow ( this ,
There's already a question on this here. But i want to know if its
I already know that most implementations use a single thread, but is there anything
I know there are dozens of questions that ask about this error, but none

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.