Some meory leaks fixed

Fixed leaks found:
* api.c: Release io_data->ptr when releasing io_data in io_free()
* api.c: Release apisock on error in api()
* util.c: Decreasing reference count on allocated JSON obects to prevent memory leak