malloc error for newbie

David dwarnold45 at suddenlink.net
Sat Jul 7 19:14:57 CEST 2007


On Jul 7, 6:27 am, John Machin <sjmac... at lexicon.net> wrote:
> On Jul 7, 4:59 pm, David <dwarnol... at suddenlink.net> wrote:
>
> > Hi,
>
> > Very new to python. When I uncomment the line
> > #        self.im.putpalette(mkpalette())
>
> Try to focus in on where the nasty is happening:
>
>    p = mkpalette()
>    # self.im.putpalette(p)
>
>
>
> > in the following code, I get the error:
>
> > python $ ./mandelbrot.py
> > Python(2860) malloc: ***  Deallocation of a pointer not malloced:
> > 0xff000000; This could be a double free(), or free() called with the
> > middle of an allocated block; Try setting environment variable
> > MallocHelp to see tools to help debug
>
> > I don't have the expertise to get by this error. Can someone help?
>
> > Thanks.
>
> > #! /usr/local/bin/python
> > # Filename: mandelbrot.py
>
> > import Image, ImagePalette
>
> Read the docs:http://effbot.org/imagingbook/imagepalette.htm
>
> They imply that len(palette) should be 769 (256*3)
>
>
>
> > def mkpalette():
> >     global palette
>
> Nothing to do with your problem, but lose the above line, and examine
> carefully whatever induced you to include it.
>
> >     palette = [0,0,0]
> >     for i in range(256):
> >         palette.extend([i*5%200+55,i*7%200+55,i*11%200+55])
> >     return palette
>
> So now len(palette) == 257*3 instead of 256*3; this may be your
> problem.
>
> HTH,
> John

That did, it. The following corrects he problem. Thanks.

def mkpalette():
    palette = [0,0,0]
    for i in range(255):
        palette.extend([i*5%200+55,i*7%200+55,i*11%200+55])
    return palette





More information about the Python-list mailing list