diff --git a/src/db.c b/src/db.c index 7d8e8eae..ae2c2ca5 100644 --- a/src/db.c +++ b/src/db.c @@ -4691,7 +4691,10 @@ queue_fetch_byposrelativetoitem(int pos, uint32_t item_id, char shuffle, struct ret = queue_fetch_bypos(pos_absolute, shuffle, queue_item, with_metadata); - DPRINTF(E_DBG, L_DB, "Fetch by pos: fetched item (id=%d, pos=%d, file-id=%d)\n", queue_item->id, queue_item->pos, queue_item->file_id); + if (ret < 0) + DPRINTF(E_LOG, L_DB, "Error fetching item by pos: pos (%d) relative to item with id (%d)\n", pos, item_id); + else + DPRINTF(E_DBG, L_DB, "Fetch by pos: fetched item (id=%d, pos=%d, file-id=%d)\n", queue_item->id, queue_item->pos, queue_item->file_id); return ret; } diff --git a/src/httpd_dacp.c b/src/httpd_dacp.c index 56a5430f..b3bad157 100644 --- a/src/httpd_dacp.c +++ b/src/httpd_dacp.c @@ -1017,6 +1017,8 @@ dacp_reply_cue_play(struct evhttp_request *req, struct evbuffer *evbuf, char **u } } + player_get_status(&status); + cuequery = evhttp_find_header(query, "query"); if (cuequery) { @@ -1031,12 +1033,9 @@ dacp_reply_cue_play(struct evhttp_request *req, struct evbuffer *evbuf, char **u return; } } - else + else if (status.status != PLAY_STOPPED) { - player_get_status(&status); - - if (status.status != PLAY_STOPPED) - player_playback_stop(); + player_playback_stop(); } param = evhttp_find_header(query, "dacp.shufflestate"); @@ -1074,7 +1073,7 @@ dacp_reply_cue_play(struct evhttp_request *req, struct evbuffer *evbuf, char **u dmap_send_error(req, "cacr", "Playback failed to start"); return; - } + } } else { @@ -1097,9 +1096,9 @@ dacp_reply_cue_play(struct evhttp_request *req, struct evbuffer *evbuf, char **u dmap_send_error(req, "cacr", "Playback failed to start"); return; + } } } - } ret = player_playback_start_byitem(queue_item); free_queue_item(queue_item, 0); @@ -1597,6 +1596,8 @@ dacp_reply_playqueuecontents(struct evhttp_request *req, struct evbuffer *evbuf, return; } + player_get_status(&status); + /* * If the span parameter is negativ make song list for Previously Played, * otherwise make song list for Up Next and begin with first song after playlist position. @@ -1626,8 +1627,6 @@ dacp_reply_playqueuecontents(struct evhttp_request *req, struct evbuffer *evbuf, } else { - player_get_status(&status); - memset(&query_params, 0, sizeof(struct query_params)); if (status.shuffle) query_params.sort = S_SHUFFLE_POS; diff --git a/src/player.c b/src/player.c index 23bbd789..32225ca2 100644 --- a/src/player.c +++ b/src/player.c @@ -1388,7 +1388,10 @@ source_read(uint8_t *buf, int len, uint64_t rtptime) { ret = source_open(ps, cur_streaming->end + 1, 0); if (ret < 0) - return -1; + { + source_free(ps); + return -1; + } ret = source_play(); if (ret < 0) @@ -2485,6 +2488,7 @@ playback_prev_bh(void *arg, int *retval) ret = source_open(ps, last_rtptime + AIRTUNES_V2_PACKET_SAMPLES, 0); if (ret < 0) { + source_free(ps); playback_abort(); *retval = -1; @@ -2556,6 +2560,7 @@ playback_next_bh(void *arg, int *retval) ret = source_open(ps, last_rtptime + AIRTUNES_V2_PACKET_SAMPLES, 0); if (ret < 0) { + source_free(ps); playback_abort(); *retval = -1; return COMMAND_END; diff --git a/src/spotify_webapi.c b/src/spotify_webapi.c index 8a9b075d..525f0cfb 100644 --- a/src/spotify_webapi.c +++ b/src/spotify_webapi.c @@ -136,7 +136,7 @@ jparse_str_from_array(json_object *array, int index, const char *key) } static void -http_client_ctx_free(struct http_client_ctx *ctx) +free_http_client_ctx(struct http_client_ctx *ctx) { if (!ctx) return; @@ -240,13 +240,19 @@ tokens_get(struct keyval *kv, const char **err) goto out_free_input_body; } + free(spotify_access_token); + spotify_access_token = NULL; + tmp = jparse_str_from_obj(haystack, "access_token"); if (tmp) - spotify_access_token = strdup(tmp); + spotify_access_token = strdup(tmp); tmp = jparse_str_from_obj(haystack, "refresh_token"); if (tmp) - spotify_refresh_token = strdup(tmp); + { + free(spotify_refresh_token); + spotify_refresh_token = strdup(tmp); + } expires_in = jparse_int_from_obj(haystack, "expires_in"); if (expires_in == 0) @@ -408,7 +414,7 @@ request_uri(struct spotify_request *request, const char *uri) void spotifywebapi_request_end(struct spotify_request *request) { - http_client_ctx_free(request->ctx); + free_http_client_ctx(request->ctx); jparse_free(request->haystack); } @@ -416,7 +422,6 @@ int spotifywebapi_request_next(struct spotify_request *request, const char *uri) { char *next_uri; - const char *tmp; int ret; if (request->ctx && !request->next_uri) @@ -444,9 +449,7 @@ spotifywebapi_request_next(struct spotify_request *request, const char *uri) return ret; request->total = jparse_int_from_obj(request->haystack, "total"); - tmp = jparse_str_from_obj(request->haystack, "next"); - if (tmp) - request->next_uri = strdup(tmp); + request->next_uri = jparse_str_from_obj(request->haystack, "next"); if (jparse_array_from_obj(request->haystack, "items", &request->items) < 0) { diff --git a/src/spotify_webapi.h b/src/spotify_webapi.h index af9efaf4..744724bc 100644 --- a/src/spotify_webapi.h +++ b/src/spotify_webapi.h @@ -91,7 +91,7 @@ struct spotify_request json_object *items; int count; int total; - char *next_uri; + const char *next_uri; int index; };