numpy/numpy — pull request #4494 by embray (2014-03-14 16:17:02+00:00)
Title: Adds missing Py_INCREF in array_boolean_subscript

This bug was introduced, as far as I can tell, in 52b4a94. It came up in the context of astropy/astropy#1987 where we were getting semi-irregular segfaults. The problem is that after this line a new array is created with `PyArray_NewFromDescr` using an existing dtype object, but it does not incref that dtype object.

A reliable way to demonstrate this bug I found was something like:

```
import numpy as np
c = np.rec.array([(1, 2, 3), (4, 5, 6)])
masked = c[np.array([True, False])]
base = masked.base
del masked, c
base.dtype
```

at this point various different things could happen, but most often it just results in a segfault.