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 6131391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:58:08+00:00 2026-05-23T16:58:08+00:00

I am using OpenCV 2.1 with codeblocks (gcc under mingw). Within my code I

  • 0

I am using OpenCV 2.1 with codeblocks (gcc under mingw). Within my code I am trying (for some sane reason) to access the imagedata within IplImage datastructure directly. Kindly refer the code snippet for more details:

int main(void)
{
    IplImage* test_image = cvLoadImage("test_image.bmp",CV_LOAD_IMAGE_GRAYSCALE);
    int mysize = test_image->height * test_image->widthStep;
    char* imagedata_ptr = NULL;

    int i   =   0;    
    imagedata_ptr = test_image->imageData;

    char* temp_buff = (char *)malloc(sizeof(mysize));
    memcpy(temp_buff,imagedata_ptr,mysize);

    free(temp_buff);
}

When I run this code it crashes. On running it in the debug mode it generates a SIGTRAP is due to heap corruption. At first I suspected that this might be a compiler related issue and hence tried running the same code in Visual Studio. But it still crashes. Thats the reason I feel it could be an OpenCV related issue.

NOTE: There are no other instances of program open, this is the only code that I am running, no threading etc is being done here.

Awaiting your comments on the same.

Regards,

Saurabh Gandhi

  • 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-05-23T16:58:09+00:00Added an answer on May 23, 2026 at 4:58 pm

    You’re not allocating enough memory, this:

    char* temp_buff = (char *)malloc(sizeof(mysize))
    

    only allocates sizeof(int) bytes (probably 4) and that’s probably a lot less than you need. Then the memcpy right after that will copy test_image->height * test_image->widthStep bytes of data into somewhere that only has space for sizeof(int) bytes and you have now scribbled all over your memory and corrupted your heap.

    I’d guess that you really want to say this:

    char *temp_buff = malloc(mysize);
    

    And don’t cast the return value from malloc, you don’t need it and it can hide problems.

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

Sidebar

Related Questions

I am trying to do some image rectification using OpenCV .I got some code
Hi I am trying to detect web cam in opencv using following code I
I am trying to do some image matching using OpenCV and am using the
am trying to calculate mean and variance using 3X3 window over image(hXw) in opencv...here
I am building an application using OpenCV that uses the webcam and runs some
I am using openCV python bindings. I am trying to show the output image
I have to code an object detector (in this case, a ball) using OpenCV.
I am doing some heavy calculations with Python (using OpenCV and Numpy) and in
I am using opencv 2.1. In my code I have a few images stored
Im trying face detection using opencv in android but I unable to load the

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.