Main assumed multi-byte characters in memory allocation but not outside of it so I removed that code and made it consistently assume single-byte characters.
Terminating character was added always to the last byte of string buffer regardless of the length of the string. Removed it and replaced malloc with calloc.
Moved variable introductions from the middle of the function to the beginning of it.
String buffer allocation didn't allocate space for terminating char. It also assumed that character size may vary but the rest of the code didn't support multi-byte characters so I changed it consistently assume single-byte characters.
mysql_backend.c, mysql_client.c free error message GWBUF after calling handleError
readconnroute.c:handleError send error message to client before returning.
readwritesplit.c:handleError don't free error message buffer anymore since the caller of handleError frees it.
gw_change_user returned error code in cases where authentication failed. That is not right behavior in that context. gw_change_user succeeds to route query and should return succees to router's routeQuery. Possible error is handled by creating error message and by feeding it to client DCB's event queue.
Added function poll.c:poll_add_epollin_event_to_dcb which adds given event and related GWBUF to given DCB. The DCB is then added to event queue list so that its even becomes executed as soon as any of the threads start to process events next time.
The problem solved is case where COM_CHANGE_USER failed due to authentication failure. An error should be sent to the client but it was sent once per failed backend authentication instead of just once.
Thread which failed in authentication bypassed router and thus replies weren't filtered out. Solution adds an event and a GWBUF including error message to DCB and the DCB is then added to event queue. Thus the error message appeares like it was an incoming event and becomes processed properly.
An addition was made to mysql_backend.c:gw_read_backend_event so that self-generated event can be processed. Even if socket read doesn't manage to read anything, function proceeds if there is enough data in DCB's readqueue.
Fix ti bug #602, http://bugs.mariadb.com/show_bug.cgi?id=602
Added function sescmd_response_complete which checks if the read data completes session command response packet(s). Function is called only if there's a sessoin command being executed.
mysql_common.c:gw_send_change_user_to_backend creates new authentication message which is to be sent to backend. GWBUG type flags were not copied from original GWBUF to new one. Thus the information that this is a session command was lost and it was processed in a wrong way. Especially replies were all routed back to client which caused misbehavior.
regexfilter.c:routeQuery called modutil_replace_SQL which resulted in multiple buffers in query GWBUF. Those weren't handled properly later. Added call for gwbug_make_contiguous.
buffer.c:gwbuf_make_contiguous: hint wasn't duplicated to new GWBUF struct. As a result hints were lost if query rewriting resulted in longer query than the original.