开发者

I *think* I have a memory leak. What now?

I created a C++ DLL function that uses several arrays to process what is eventually image data. I'm attempting to pass these arrays by reference, do the computation, and pass the output back by reference in a pre-allocated array. Within the function I use the Intel Performance Primitives including ippsMalloc and ippsFree:

Process.dll

int __stdcall ProcessImage(const float *Ref, const float *Source, float *Dest, const float *x, const float *xi, const int row, const int col, const int DFTlen, const int IMGlen)
{
int k, l;
IppStatus status;
IppsDFTSpec_R_32f *spec;
Ipp32f *y = ippsMalloc_32f(row),
    *yi = ippsMalloc_32f(DFTlen),
    *X = ippsMalloc_32f(DFTlen),
    *R = ippsMalloc_32f(DFTlen);

for (int i = 0; i < col; i++)
{
    for (int j = 0; j < row; j++)
        y[j] = Source[j + (row * i)];
    status = ippsSub_32f_I(Ref, y, row);

            // Some interpolation calculations calculations here

    status = ippsDFTInitAlloc_R_32f(&spec, DFTlen, IPP_FFT_DIV_INV_BY_N, ippAlgHintNone);
    status = ippsDFTFwd_RToCCS_32f(yi, X, spec, NULL);
    status = ippsMagnitude_32fc( (Ipp32fc*)X, R, DFTlen);

    for (int m = 0; m < IMGlen; m++)
        Dest[m + (IMGlen * i)] = 10 * log10(R[m]);
}
_CrtDumpMemoryLeaks();

ippsDFTFree_R_32f(spec);
ippsFree(y);
ippsFree(yi);
ippsFree(X);
ippsFree(R);
return(status);
}

The function call looks like this:

for (int i = 0; i < Frames; i++)
    ProcessFrame(&ref[i * FrameSize], &source[i * FrameSize], &dest[i * FrameSize], mX, mXi, NumPixels, Alines, DFTLength, IMGLength);

The function does not fail and produces the desired output for up to 6 images, more than that and it dies with:

First-chance exception at 0x022930e0 in DLL_test.exe: 0xC0000005: Access violation reading location 0x1cdda000.

I've attempte开发者_StackOverflow中文版d to debug the program, unfortunately VS reports that the call stack location is in an IPP DLL with "No Source Available". It consistently fails when calling ippMagnitude32fc( (Ipp32fc*)X, R, DFTlen)

Which leads me to my questions: Is this a memory leak? If so, can anybody see where the leak is located? If not, can somebody suggest how to go about debugging this problem?


To answer your first question, no that's not a memory leak, that's a memory corruption. A memory leak is when you don't free the memory used, and so , the memory usage is growing up. That doesn't make the program to not work, but only end up using too much memory, which results in the computer being really slow (swaping) and ultimately any program crashing with a 'Not enough memory error'. What you have is basic pointer error, as it happend all the time in C++. Explain how to debug is hard, I suggest you add a breakpoint just before in crash, and try to see what's wrong.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜