malloc error for newbie

D

David

Hi,

Very new to python. When I uncomment the line
# self.im.putpalette(mkpalette())
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

def mkpalette():
global palette
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

class Mandelbrot:

def __init__(self,filename='mandelbrot.png',
size=(512,512),
n=64,
box=((-2,1.25), (0.5,-1.25))):
self.filename=filename
self.size=size
self.n=n
self.uleft=box[0]
self.lright=box[1]
self.width=self.lright[0]-self.uleft[0]
self.height=self.uleft[1]-self.lright[1]

def newimage(self):
self.im=Image.new('P', self.size)
# self.im.putpalette(mkpalette())

def compute(self):
self.newimage()

def test():
f=Mandelbrot(filename='mandelbrot.png',
size=(512,512),
n=64,
box=((-2,1.25), (0.5,-1.25)))
f.compute()

if __name__=='__main__':
test()
 
J

John Machin

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
 
D

David

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?

#! /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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top