Drupal adds PHP error messages to the session variable "messages".
This variable is displayed and emptied when normal HTML pages are
displayed. However, ReST calls do not display these messages, and
the errors will keep accumulating. After enough ReST calls, the
message variable becomes large enough (>24MB) for the mysql client to
abort.

This patch clears the messages variable after each ReST call.