Note that there are some explanatory texts on larger screens.

plurals
  1. POPass by pointer, memory leak
    primarykey
    data
    text
    <p><em>NOTE: Initially I though that a section of code was causing a leak but that turned out to be incorrect. Hence the comments below. I have updated the question</em></p> <p>Possible Solution: I managed to solve this. What I did was move all initializations to the head of the function. Listed them out on a piece of paper and scratched em off as I came across the corresponding delete code. This way 1. I did not miss any deletions 2. Made sure I was not initializing anything inside the loop Managed to eliminate all but a few bytes of leak. Updated code: <a href="http://sharetext.org/gPJf" rel="nofollow">http://sharetext.org/gPJf</a> The "before" code you can find below:</p> <hr> <p>The function in which I am facing errors is this one: <a href="http://sharetext.org/3gq0" rel="nofollow">http://sharetext.org/3gq0</a></p> <p>From the comments I gather that the initialization and deletion may not be proper. This is the code responsible for the tast</p> <pre><code>float** CMemAlloc::init_2Dfloat(int rows,int cols) { float **a; a=new float*[rows]; for(int j=0;j&lt;rows;j++) a[j]=new float[cols]; for(int i=0;i&lt;rows;i++) for(int j=0;j&lt;cols;j++) a[i][j]=0.0; return a; } void CMemAlloc::del_float(float **a,int rows) { if(a!=NULL) { for (int i = 0; i &lt;rows; i++) { delete[] a[i]; a[i] = NULL; } delete[] a; a=NULL; } else { return; } } </code></pre> <p>I suspect this function pair is malfunctioning:</p> <pre><code>CCoarseFun::window** CCoarseFun::init_2Dwin(int rows,int cols) { window** a; a=new window*[rows]; for(int j=0;j&lt;rows;j++) a[j]=new window[cols]; for(int i=0;i&lt;rows;i++) { for(int j=0;j&lt;cols;j++) { a[i][j].line_high=0; a[i][j].line_low=0; a[i][j].pixel_high=0; a[i][j].pixel_low=0; } } return a; } void CCoarseFun::del_win(window ** a, int rows) { for(int i=0;i&lt;rows;i++) { delete [] a[i]; a[i] = NULL; } delete[] a; a=NULL; } </code></pre> <p>Could there be an error here? </p> <p>NOTE: I have put trace statements at various points and am printing the address of "block". Here is the output: <a href="http://sharetext.org/ODSv" rel="nofollow">http://sharetext.org/ODSv</a></p> <p>What I am currently trying is to remove all initializations from inside loops. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload