[AstroPy] strange error with ctypes

James Turner jturner at gemini.edu
Thu Feb 16 12:52:17 EST 2012

> Investigating further, the error occurs when executing a free() instruction. I
> don't see how this could create an error !

I believe it could cause an error if either the pointer Line has been
changed, so you are trying to free the wrong memory, or something has
inadvertently overwritten the memory you're trying to free (along with
a few bytes of information like the length of the array that malloc
keeps just before the allocated block). Fortunately the malloc and
free happen close together, so there aren't many likely culprits. My C
is sufficiently rusty that I might not spot a problem with the code
you sent but I'd have to suspect that one of the 3 calls in your for
loop is writing out of bounds, perhaps only when a certain rounding
condition occurs (explaining the once-in-a-few-hundred-thousand

Someone more on the ball with C and Windows might have better input,
but maybe that gives you an idea where to get started...



> The piece of C code looks like
> Line = (double *)malloc((size_t)(Width * (long)sizeof(double)));
> if (Line == (double *)NULL) {
> printf("Row allocation failed\n");
> return(1);
> }
> for (y = 0L; y < Height; y++) {
> GetRow(Image, y, Line, Width);
> ConvertToInterpolationCoefficients(Line, Width, Pole, NbPoles, DBL_EPSILON);
> PutRow(Image, y, Line, Width);
> }
> free(Line);
> And the error occurs at the statement free(Line).
> I am starting to suspect something nasty happening with ctypes. Or maybe I am
> missing something very basic ? Any suggestion ? I am sure there are experienced
> programmers on this list, who could advice me.
> Many thanks for your help and patience reading me
> Kind regards
> Jerome Caron
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy

More information about the AstroPy mailing list