help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-gsl] Freeing up memory used by GSL matrix


From: James Bergstra
Subject: Re: [Help-gsl] Freeing up memory used by GSL matrix
Date: Mon, 12 Jun 2006 06:36:10 -0400
User-agent: Mutt/1.4.2.1i

On Mon, Jun 12, 2006 at 12:15:42AM -0500, address@hidden wrote:
> I am trying to figure out a way to efficiently free the memory after a gsl
> matrix is no longer being used. Of course, one could call
> gsl_matrix_free(). However in my case, the block pointer may or may not be
> allocated.
> 
> A code snippet follows:
> 
> 
> gsl_matrix *matQ_temp = gsl_matrix_alloc(1,1);
> gsl_block_free(matQ_temp->block);
> matQ_temp->blcok = 0;
> 
>   if (matQ_temp->block!=0){
>     std::cout<<"true"<<std::endl;
>     gsl_matrix_free(matQ_temp);
>   }
>   else{
>     std::cout<<"false"<<std::endl;
>     free(matQ_temp->data);
>   }
> 
> When running this I get the following o/p:
> 
> false
> *** glibc detected *** double free or corruption (!prev): 0x081b39a8 ***
> Aborted
> 
> 
> I thought even after gsl_block_free has been called, the data pointer
> needs to be freed. If yes, then why am I getting this error? Or does
> gsl_block_free() automatically free the data pointer as well?
> 
> Also, is there anything else I need to do to free the memory?

gsl_block_free not only deallocates the block itself, but also the data that it
encapsulates.  Your matrix buffer was free'd on line 2, so that's why you get a
double free in the else block.



-- 
James Bergstra
http://www-etud.iro.umontreal.ca/~bergstrj





reply via email to

[Prev in Thread] Current Thread [Next in Thread]