libxl_qmp: Move the buffer realloc to the same scope level as read
authorAnthony PERARD <anthony.perard@citrix.com>
Fri, 27 Jul 2018 14:05:47 +0000 (15:05 +0100)
committerWei Liu <wei.liu2@citrix.com>
Mon, 30 Jul 2018 13:46:32 +0000 (14:46 +0100)
commit75ac495dc9d6aa3d6240bfab1adbdc0d0f8bc403
treee01f9445e0b15f8530f99b7e12586cb4f11ad06a
parent22ef662c7a4c812bbf9132d004cbf5ccf0bfdd5f
libxl_qmp: Move the buffer realloc to the same scope level as read

In qmp_next(), the inner loop should only try to parse messages from
QMP, if there is more than one.

The handling of the receive buffer ('incomplete'), should be done at the
same scope level as read(). It doesn't need to be handle more that once
after a read.

Before this patch, when on message what handled, the inner loop would
restart by adding the 'buffer' into 'incomplete' (after reallocation).
Since 'rd' was not reset, the buffer would be strcat a second time.
After that, the stream from the QMP server would have syntax error, and
the parsor would throw errors.

This is unlikely to happen as the receive buffer is very large. And
receiving two messages in a row is unlikely. In the current case, this
could be an event and a response to a command.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxl/libxl_qmp.c