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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:23:03+00:00 2026-05-25T23:23:03+00:00

I have an problem freeing up memory allocated for an IplImage .I have given

  • 0

I have an problem freeing up memory allocated for an IplImage.I have given a similar situation as in my application below.(it reflects the same bug occurs in my application.)

But instead of the line

char* originalData=loadedImage->imageData;

I get my “originalData” from a QT QImage class.
Code crashes at the line where I free “image_gray”.

cvReleaseImage(&img_gray); // <-- crashes

Error message –

OpenCV Error: Assertion failed (udata < (uchar*)ptr && ((uchar*)ptr –
udata) <= (ptrdiff_t)(sizeof(void*)+16)) in fastFree, file
C:\opt\OpenCV-2.2.0\modules\co e\src\alloc.cpp, line 76 terminate
called after throwing an instance of ‘cv::Exception’ what():
C:\opt\OpenCV-2.2.0\modules\core\src\alloc.cpp:76: error: (-215) uda a
< (uchar*)ptr && ((uchar*)ptr – udata) <=
(ptrdiff_t)(sizeof(void*)+16) in fu ction fastFree

But if I use cvReleaseImageHeader() instead, if works fine but leaving a memory leak.

Any suggestions please?

void test2( char *imageFileName)
{



    IplImage *loadedImage=cvLoadImage(imageFileName);

    int xsize=loadedImage->width;
    int ysize=loadedImage->height;
    int totalBytes=xsize*ysize;


    //In my application this "originalData" data comes from a QT QImage.
    char* originalData=loadedImage->imageData;
    unsigned char* datacopy = new unsigned char [totalBytes];

    memcpy(datacopy, originalData, totalBytes);

    IplImage* img_gray = cvCreateImage( cvSize(xsize, ysize), IPL_DEPTH_8U, 1 );
    IplImage* img_gray_copy = cvCreateImage( cvSize(xsize, ysize), IPL_DEPTH_8U, 1 );
    IplImage* img_edge = cvCreateImage( cvSize(xsize, ysize), IPL_DEPTH_8U, 1 );

    IplImage* img_mask = cvCreateImage(cvSize(xsize, ysize), IPL_DEPTH_8U, 1);

    cvSet(img_mask, cvScalar(255));
    cvSet(img_gray_copy, cvScalar(255));

    cvSetZero(img_mask);


    cvSetData(img_gray, datacopy, xsize);


    cvCopy(img_gray, img_gray_copy, img_mask);

    //cvThreshold(img_gray_copy, img_edge, threshold, 255, CV_THRESH_BINARY_INV);
    //cvFindContours(img_edge, storage, contours, sizeof(CvContour), CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE);




    cvReleaseImage(&img_gray); /// <--- this crashes the application
    //cvReleaseImageHeader(&img_gray); //<--- this works.but leaving a memory leak ???
    cvReleaseImage(&img_gray_copy);

    cvReleaseImage(&img_edge);
    cvReleaseImage(&img_mask);



}
  • 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-25T23:23:03+00:00Added an answer on May 25, 2026 at 11:23 pm

    Ok found the issue.
    I should have used cvCreateImageHeader() for img_gray .And then manually delete allocated memory.

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

Sidebar

Related Questions

I have a situation like below in which I have some problem in freeing
I have a problem where my application aggressively consumes memory to a thrashing point
I have a problem freeing up memory of an object.Here is my code: void
I have a lot of memory allocations and the same number of FreeMem calls.
I have trouble deallocating memory that I allocated using malloc. The program runs fine
I have a .NET/native C++ application. Currently, the C++ code allocates memory on the
this is really frustrating me. this problem occurs when I have a particularly large
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am

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.