Resolve realloc mistake and possible NP dereferences in lib/utils.c

This patches resolves the following issues in lib/utils/strsplit_by_space and in
lib/utils/strsplit_by_char:

  * Check if the pointer to the passed length parameter is valid
  otherwise it will cause a NULL pointer dereference

  * If the allocation done by realloc fails the current code would
  overwrite the pointer to the previously allocated memory with NULL, thus it is
  not reachable anymore. Therefore we need to store the return value of realloc
  in a temporary variable and then check it if the realloc call has succeeded or
  not. On failure we free the previously allocated memory and return an error.
Merge pull request #517 from mlq/hotfix/lib-utils-realloc-np-dereferences

Resolve realloc mistake and possible NP dereferences in lib/utils.c