fix allocation in line plugin

use more efficient realloc, and do not alloc every time
fix other memleak