Index: main/asterisk.c =================================================================== --- main/asterisk.c (revision 172517) +++ main/asterisk.c (working copy) @@ -2394,11 +2394,12 @@ int nummatches = 0; char **matches; int retval = CC_ERROR; - char buf[2048]; + char buf[2048], savechr; int res; LineInfo *lf = (LineInfo *)el_line(editline); + savechr = *(char *)lf->cursor; *(char *)lf->cursor = '\0'; ptr = (char *)lf->cursor; if (ptr) { @@ -2424,8 +2425,10 @@ char *mbuf; int mlen = 0, maxmbuf = 2048; /* Start with a 2048 byte buffer */ - if (!(mbuf = ast_malloc(maxmbuf))) + if (!(mbuf = ast_malloc(maxmbuf))) { + lf->cursor[0] = savechr; return (char *)(CC_ERROR); + } snprintf(buf, sizeof(buf), "_COMMAND MATCHESARRAY \"%s\" \"%s\"", lf->buffer, ptr); fdsend(ast_consock, buf); res = 0; @@ -2434,8 +2437,10 @@ if (mlen + 1024 > maxmbuf) { /* Every step increment buffer 1024 bytes */ maxmbuf += 1024; - if (!(mbuf = ast_realloc(mbuf, maxmbuf))) + if (!(mbuf = ast_realloc(mbuf, maxmbuf))) { + lf->cursor[0] = savechr; return (char *)(CC_ERROR); + } } /* Only read 1024 bytes at a time */ res = read(ast_consock, mbuf + mlen, 1024); @@ -2495,6 +2500,8 @@ ast_free(matches); } + lf->cursor[0] = savechr; + return (char *)(long)retval; }