Switch to malloc'ing each node individually rather than trying to guess up front the total buffer space needed.