在nc_message.c中定义了局部变量sendv,且定义为栈上空间,在后续调用中array_push(&sendv),如果array的size达到预定义的值,在array_push会对send->elem进行realloc。
问题就出现了,sendv是栈上变量,不允许对其进行realloc(只有堆变量才可以)。知道原因了,修复方案很简单,send改为malloc方式获得。
代码如下:
... struct array sendv; /* send iovec */ ... ciov = array_push(&sendv); | | array_push(struct array *a) { ... if (a->nelem == a->nalloc) { /* the array is full; allocate new array */ size = a->size * a->nalloc; new = nc_realloc(a->elem, 2 * size); }