astropy/astropy — pull request #2361 by mdboom (2014-04-24 00:20:24+00:00)
Title: WCS.sub fails on adding a new axis

In trying to extend the WCS utilities to create new axis (or merge two independent WCS), I came across this error:

```
In [1]: w = wcs.WCS()

In [2]: w.naxis
Out[2]: 2

In [3]: w.sub([1,2,0])
python(266,0x7fff7eb43310) malloc: *** error for object 0x10773ac18: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
Out[3]: Abort trap: 6
```

According to the WCS docs, "Use an axis number of 0 to create a new axis using the defaults." (see http://www.atnf.csiro.au/people/mcalabre/WCS/wcslib/wcs_8h.html#a864c99fef9f3eee29085ce42d0ee0d64 or http://astropy.readthedocs.org/en/latest/api/astropy.wcs.Wcsprm.html#astropy.wcs.Wcsprm.sub)

Note that this is an intermittent error; I got it 2 out of 3 attempts.

I suspect this is an issue with wcslib rather than `astropy.wcs`, since the same occurs using the c-wrapped routine:
```
In [2]: w.wcs.sub([1,2,0])
```

but I'm not sure - it could have to do with the memory allocation used by the python wrapper.

@mdboom - can you advise?