memcached_server_response_increment(ptr);
return MEMCACHED_STAT;
}
- else if (buffer[1] == 'E')
+ else if (buffer[1] == 'E') /* SERVER_ERROR */
{
- /* SERVER_ERROR */
+ char *rel_ptr;
char *startptr= buffer + 13, *endptr= startptr;
+
while (*endptr != '\r' && *endptr != '\n') endptr++;
- if (ptr->cached_server_error) ptr->root->call_free(ptr->root, ptr->cached_server_error);
- ptr->cached_server_error= ptr->root->call_malloc(ptr->root, endptr - startptr + 1);
+
+ /*
+ Yes, we could make this "efficent" but to do that we would need
+ to maintain more state for the size of the buffer. Why waste
+ memory in the struct, which is important, for something that
+ rarely should happen?
+ */
+ rel_ptr= (char *)ptr->root->call_realloc(ptr->root, ptr->cached_server_error, endptr - startptr + 1);
+
+ if (rel_ptr == NULL)
+ {
+ /* If we happened to have some memory, we just null it since we don't know the size */
+ if (ptr->cached_server_error)
+ ptr->cached_server_error[0]= 0;
+ return MEMCACHED_SERVER_ERROR;
+ }
+ ptr->cached_server_error= rel_ptr;
+
memcpy(ptr->cached_server_error, startptr, endptr - startptr);
ptr->cached_server_error[endptr - startptr]= 0;
return MEMCACHED_SERVER_ERROR;