[scilab-Users] problem with free function
Collewet Guylaine
guylaine.collewet at cemagref.fr
Mon Feb 14 12:12:39 CET 2011
Hi,
Thank you for your help
The debugging mode allowed me to fix the problem
May be it can be useful for someone else :
the calloc was called in a function in one dll (the dll corresponding to the "c" files) and the free was called by a function belonging to another dll (the dll corresponding to the "sci_gateway" files). This led to an error in the heap of the pointer detected by _CtlIsValidHeadPointer
If the calloc and free are called in the same function, scilab does not crash anymore
Guylaine
De : Allan CORNET [mailto:allan.cornet at scilab.org]
Envoyé : lundi 14 février 2011 08:24
À : users at lists.scilab.org
Objet : RE: [scilab-Users] problem with free function
Hi,
You can debug your code with Visual studio :
http://wiki.scilab.org/How_to_debug_an_external_source_code_linked_to_scilab_with_Visual_Studio
Allan
De : Collewet Guylaine [mailto:guylaine.collewet at cemagref.fr]
Envoyé : vendredi 11 février 2011 17:22
À : users at lists.scilab.org
Objet : [scilab-Users] problem with free function
Hello,
I have a problem with the "free" function which makes scilab crash
I wrote two functions "sci_imdilate" and "image_dilate"
sci_imdilate is the interface between scilab and the function image_dilate
the memory pointed by l_dilated_image (see the code below) is allocated by image_dilate and I'd like to free it in sci_imdilate
however, a call to free makes scilab crash
If I remove the "free", the whole function works properly
I cannot undersand why
Does someone see my mistake ?
I am working with scilab 5.2.2 32 bits on windows 7 (64 bits machine)
Regards
Guylaine Collewet
/////////////////////////
// function sci_imdilate
///////////////////////
double *l_dilated_image;
.../...
dilate_image(&l_image[0], m_image, n_image, &l_kernel[0], m_kernel, n_kernel, &l_dilated_image, &l_mask[0], &ierr);
createMatrixOfDouble(pvApiCtx, 4, m_image, n_image, l_dilated_image);
if(l_dilated_image) {
free(l_dilated_image);
}
/////////////////////////
// function dilate_image
/////////////////////////
int dilate_image(double *image, int width, int height, double *kernel, int kernel_width, int kernel_height, double **dilated_image, double *mask, int *ierr)
{
.../...
if (!(*dilated_image = (double*)calloc(1, sizeof(double)*width*height)))
{
*ierr=1;
return(-1);
}
.../...
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20110214/d888e7dc/attachment.htm>
More information about the users
mailing list