dvipng error with usetex

I am not a usetex user, but in testing mpl on a linux box I got a new
error for dvipng. I hadn't seen this on this box before (it used to
work there) but I am not suspecting an mpl bug at this point, rather a
bug on the system. I don't really know, but others have reported
similar dvipng bugs unrelated to mpl on ubuntu so I suspect the
problem lies there. I am posting it here as a warning to others, and
also in case anyone has any idea how to fix, debug or diagnose it. I
would like to fix it because this is my primary machine for building
and testing and updating the docs, so I'd like to have usetex working.

If you google

  glibc detected *** dvipng: free(): invalid pointer

there are a number of but reports

And now the bug, using the mpl 1.0.0 release

jdhunter@...687...:pylab_examples> dvipng --version
This is dvipng 1.11 Copyright 2002-2008 Jan-Ake Larsson
dvipng 1.11
kpathsea version 3.5.4
Compiled with Freetype 2.3.5
Using libft 2.3.11
Copyright (C) 2002-2008 Jan-Ake Larsson.
There is NO warranty. You may redistribute this software
under the terms of the GNU Lesser General Public License
version 3, see the COPYING file in the dvipng distribution
or <http://www.gnu.org/licenses/>.
jdhunter@...687...:pylab_examples> uname -a Linux uqbar 2.6.32-23-generic
#37-Ubuntu SMP Fri Jun 11 08:03:28 UTC 2010 x86_64 GNU/Linux
jdhunter@...687...:pylab_examples>
PYTHONPATH=~/dev/lib/python2.6/site-packages/ python tex_demo.py
--debug-annoying -dAgg
*** glibc detected *** dvipng: free(): invalid pointer: 0x0000000001b365b1 ***
======= Backtrace: =========
/lib/libc.so.6(+0x775b6)[0x7fe691b7e5b6]
/lib/libc.so.6(cfree+0x73)[0x7fe691b84e53]
dvipng[0x41480b]
dvipng[0x414a6a]
dvipng[0x412296]
dvipng[0x4071ce]
dvipng[0x405908]
dvipng[0x405a6c]
dvipng[0x40298c]
/lib/libc.so.6(__libc_start_main+0xfd)[0x7fe691b25c4d]
dvipng[0x402859]
======= Memory map: ========
00400000-00422000 r-xp 00000000 08:05 6390264
  /home/jdhunter/dev/bin/dvipng
00621000-00623000 rw-p 00021000 08:05 6390264
  /home/jdhunter/dev/bin/dvipng
00623000-00627000 rw-p 00000000 00:00 0
01965000-01b60000 rw-p 00000000 00:00 0 [heap]
7fe68c000000-7fe68c021000 rw-p 00000000 00:00 0
7fe68c021000-7fe690000000 ---p 00000000 00:00 0
7fe6904fd000-7fe690513000 r-xp 00000000 08:02 5160983
  /lib/libgcc_s.so.1
7fe690513000-7fe690712000 ---p 00016000 08:02 5160983
  /lib/libgcc_s.so.1
7fe690712000-7fe690713000 r--p 00015000 08:02 5160983
  /lib/libgcc_s.so.1
7fe690713000-7fe690714000 rw-p 00016000 08:02 5160983
  /lib/libgcc_s.so.1
7fe690714000-7fe690719000 r-xp 00000000 08:02 1433640
  /usr/lib/libXdmcp.so.6.0.0
7fe690719000-7fe690918000 ---p 00005000 08:02 1433640
  /usr/lib/libXdmcp.so.6.0.0
7fe690918000-7fe690919000 r--p 00004000 08:02 1433640
  /usr/lib/libXdmcp.so.6.0.0
7fe690919000-7fe69091a000 rw-p 00005000 08:02 1433640
  /usr/lib/libXdmcp.so.6.0.0
7fe69091a000-7fe69091c000 r-xp 00000000 08:02 2787952
  /usr/lib/libXau.so.6.0.0
7fe69091c000-7fe690b1c000 ---p 00002000 08:02 2787952
  /usr/lib/libXau.so.6.0.0
7fe690b1c000-7fe690b1d000 r--p 00002000 08:02 2787952
  /usr/lib/libXau.so.6.0.0
7fe690b1d000-7fe690b1e000 rw-p 00003000 08:02 2787952
  /usr/lib/libXau.so.6.0.0
7fe690b1e000-7fe690b44000 r-xp 00000000 08:02 5161212
  /lib/libexpat.so.1.5.2
7fe690b44000-7fe690d44000 ---p 00026000 08:02 5161212
  /lib/libexpat.so.1.5.2
7fe690d44000-7fe690d46000 r--p 00026000 08:02 5161212
  /lib/libexpat.so.1.5.2
7fe690d46000-7fe690d47000 rw-p 00028000 08:02 5161212
  /lib/libexpat.so.1.5.2
7fe690d47000-7fe690d49000 r-xp 00000000 08:02 5163771
  /lib/libdl-2.11.1.so
7fe690d49000-7fe690f49000 ---p 00002000 08:02 5163771
  /lib/libdl-2.11.1.so
7fe690f49000-7fe690f4a000 r--p 00002000 08:02 5163771
  /lib/libdl-2.11.1.so
7fe690f4a000-7fe690f4b000 rw-p 00003000 08:02 5163771
  /lib/libdl-2.11.1.so
7fe690f4b000-7fe690f66000 r-xp 00000000 08:02 2788524
  /usr/lib/libxcb.so.1.1.0
7fe690f66000-7fe691165000 ---p 0001b000 08:02 2788524
  /usr/lib/libxcb.so.1.1.0
7fe691165000-7fe691166000 r--p 0001a000 08:02 2788524
  /usr/lib/libxcb.so.1.1.0
7fe691166000-7fe691167000 rw-p 0001b000 08:02 2788524
  /usr/lib/libxcb.so.1.1.0
7fe691167000-7fe69119a000 r-xp 00000000 08:02 2786757
  /usr/lib/libfontconfig.so.1.4.4
7fe69119a000-7fe69139a000 ---p 00033000 08:02 2786757
  /usr/lib/libfontconfig.so.1.4.4
7fe69139a000-7fe69139b000 r--p 00033000 08:02 2786757
  /usr/lib/libfontconfig.so.1.4.4
7fe69139b000-7fe69139c000 rw-p 00034000 08:02 2786757
  /usr/lib/libfontconfig.so.1.4.4
7fe69139c000-7fe6913bf000 r-xp 00000000 08:02 2791065
  /usr/lib/libjpeg.so.62.0.0
7fe6913bf000-7fe6915be000 ---p 00023000 08:02 2791065
  /usr/lib/libjpeg.so.62.0.0
7fe6915be000-7fe6915bf000 r--p 00022000 08:02 2791065
  /usr/lib/libjpeg.so.62.0.0
7fe6915bf000-7fe6915c0000 rw-p 00023000 08:02 2791065
  /usr/lib/libjpeg.so.62.0.0
7fe6915c0000-7fe6916f1000 r-xp 00000000 08:02 2789161
  /usr/lib/libX11.so.6.3.0
7fe6916f1000-7fe6918f1000 ---p 00131000 08:02 2789161
  /usr/lib/libX11.so.6.3.0
7fe6918f1000-7fe6918f2000 r--p 00131000 08:02 2789161
  /usr/lib/libX11.so.6.3.0
7fe6918f2000-7fe6918f6000 rw-p 00132000 08:02 2789161
  /usr/lib/libX11.so.6.3.0
7fe6918f6000-7fe691906000 r-xp 00000000 08:02 2790617
  /usr/lib/libXpm.so.4.11.0
7fe691906000-7fe691b05000 ---p 00010000 08:02 2790617
  /usr/lib/libXpm.so.4.11.0
7fe691b05000-7fe691b06000 r--p 0000f000 08:02 2790617
  /usr/lib/libXpm.so.4.11.0
7fe691b06000-7fe691b07000 rw-p 00010000 08:02 2790617
  /usr/lib/libXpm.so.4.11.0
7fe691b07000-7fe691c7f000 r-xp 00000000 08:02 5161404
  /lib/libc-2.11.1.so
7fe691c7f000-7fe691e7f000 ---p 00178000 08:02 5161404
  /lib/libc-2.11.1.so
7fe691e7f000-7fe691e83000 r--p 00178000 08:02 5161404
  /lib/libc-2.11.1.so
7fe691e83000-7fe691e84000 rw-p 0017c000 08:02 5161404
  /lib/libc-2.11.1.so
7fe691e84000-7fe691e89000 rw-p 00000000 00:00 0
7fe691e89000-7fe691f0b000 r-xp 00000000 08:02 5163772
  /lib/libm-2.11.1.so
7fe691f0b000-7fe69210a000 ---p 00082000 08:02 5163772
  /lib/libm-2.11.1.so
7fe69210a000-7fe69210b000 r--p 00081000 08:02 5163772
  /lib/libm-2.11.1.so
7fe69210b000-7fe69210c000 rw-p 00082000 08:02 5163772
  /lib/libm-2.11.1.so
7fe69210c000-7fe692122000 r-xp 00000000 08:02 5161322
  /lib/libz.so.1.2.3.3
7fe692122000-7fe692321000 ---p 00016000 08:02 5161322
  /lib/libz.so.1.2.3.3
7fe692321000-7fe692322000 r--p 00015000 08:02 5161322
  /lib/libz.so.1.2.3.3
7fe692322000-7fe692323000 rw-p 00016000 08:02 5161322
  /lib/libz.so.1.2.3.3
7fe692323000-7fe692348000 r-xp 00000000 08:02 5161357
  /lib/libpng12.so.0.42.0
7fe692348000-7fe692548000 ---p 00025000 08:02 5161357
  /lib/libpng12.so.0.42.0
7fe692548000-7fe692549000 r--p 00025000 08:02 5161357
  /lib/libpng12.so.0.42.0Aborted
Traceback (most recent call last):
  File "tex_demo.py", line 32, in <module>
    savefig('tex_demo')
  File "/home/jdhunter/dev/lib/python2.6/site-packages/matplotlib/pyplot.py",
line 353, in savefig
    return fig.savefig(*args, **kwargs)
  File "/home/jdhunter/dev/lib/python2.6/site-packages/matplotlib/figure.py",
line 1084, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/home/jdhunter/dev/lib/python2.6/site-packages/matplotlib/backend_bases.py",
line 1859, in print_figure
    **kwargs)
  File "/home/jdhunter/dev/lib/python2.6/site-packages/matplotlib/backends/backend_agg.py",
line 438, in print_png
    FigureCanvasAgg.draw(self)
  File "/home/jdhunter/dev/lib/python2.6/site-packages/matplotlib/backends/backend_agg.py",
line 394, in draw
    self.figure.draw(self.renderer)
  File "/home/jdhunter/dev/lib/python2.6/site-packages/matplotlib/artist.py",
line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/home/jdhunter/dev/lib/python2.6/site-packages/matplotlib/figure.py",
line 798, in draw
    func(*args)
  File "/home/jdhunter/dev/lib/python2.6/site-packages/matplotlib/artist.py",
line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/home/jdhunter/dev/lib/python2.6/site-packages/matplotlib/axes.py",
line 1892, in draw
    a.draw(renderer)
  File "/home/jdhunter/dev/lib/python2.6/site-packages/matplotlib/artist.py",
line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/home/jdhunter/dev/lib/python2.6/site-packages/matplotlib/axis.py",
line 806, in draw
    tick.draw(renderer)
  File "/home/jdhunter/dev/lib/python2.6/site-packages/matplotlib/artist.py",
line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/home/jdhunter/dev/lib/python2.6/site-packages/matplotlib/axis.py",
line 197, in draw
    self.label1.draw(renderer)
  File "/home/jdhunter/dev/lib/python2.6/site-packages/matplotlib/artist.py",
line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/home/jdhunter/dev/lib/python2.6/site-packages/matplotlib/text.py",
line 567, in draw
    self._fontproperties, angle)
  File "/home/jdhunter/dev/lib/python2.6/site-packages/matplotlib/backends/backend_agg.py",
line 198, in draw_tex
    Z = texmanager.get_grey(s, size, self.dpi)
  File "/home/jdhunter/dev/lib/python2.6/site-packages/matplotlib/texmanager.py",
line 513, in get_grey
    pngfile = self.make_png(tex, fontsize, dpi)
  File "/home/jdhunter/dev/lib/python2.6/site-packages/matplotlib/texmanager.py",
line 459, in make_png
    \n\n'% dvifile + report)
RuntimeError: dvipng was not able to process the flowing file:
/home/jdhunter/.matplotlib/tex.cache/3751fe08829ac873c509bb548895020f.dvi
Here is the full report generated by dvipng:

This is dvipng 1.11 Copyright 2002-2008 Jan-Ake Larsson