Rework error handling in daap_reply_playlists()

Kill a bit of code duplication in the error handling.
This commit is contained in:
Ace Jones 2010-01-10 14:40:03 +01:00 committed by Julien BLACHE
parent ac82b176a0
commit e033d35195
1 changed files with 20 additions and 24 deletions

View File

@ -1367,9 +1367,7 @@ daap_reply_playlists(struct evhttp_request *req, struct evbuffer *evbuf, char **
DPRINTF(E_LOG, L_DAAP, "Could not expand evbuffer for DMAP playlist list\n");
daap_send_error(req, "aply", "Out of memory");
evbuffer_free(playlistlist);
return;
goto out_list_free;
}
playlist = evbuffer_new();
@ -1378,9 +1376,7 @@ daap_reply_playlists(struct evhttp_request *req, struct evbuffer *evbuf, char **
DPRINTF(E_LOG, L_DAAP, "Could not create evbuffer for DMAP playlist block\n");
daap_send_error(req, "aply", "Out of memory");
evbuffer_free(playlistlist);
return;
goto out_list_free;
}
/* The buffer will expand if needed */
@ -1390,10 +1386,7 @@ daap_reply_playlists(struct evhttp_request *req, struct evbuffer *evbuf, char **
DPRINTF(E_LOG, L_DAAP, "Could not expand evbuffer for DMAP playlist block\n");
daap_send_error(req, "aply", "Out of memory");
evbuffer_free(playlist);
evbuffer_free(playlistlist);
return;
goto out_pl_free;
}
param = evhttp_find_header(query, "meta");
@ -1409,9 +1402,7 @@ daap_reply_playlists(struct evhttp_request *req, struct evbuffer *evbuf, char **
{
DPRINTF(E_LOG, L_DAAP, "Failed to parse meta parameter in DAAP query\n");
evbuffer_free(playlist);
evbuffer_free(playlistlist);
return;
goto out_pl_free;
}
memset(&qp, 0, sizeof(struct query_params));
@ -1424,13 +1415,7 @@ daap_reply_playlists(struct evhttp_request *req, struct evbuffer *evbuf, char **
DPRINTF(E_LOG, L_DAAP, "Could not start query\n");
daap_send_error(req, "aply", "Could not start query");
free(meta);
evbuffer_free(playlist);
evbuffer_free(playlistlist);
if (qp.filter)
free(qp.filter);
return;
goto out_query_free;
}
npls = 0;
@ -1519,8 +1504,7 @@ daap_reply_playlists(struct evhttp_request *req, struct evbuffer *evbuf, char **
daap_send_error(req, "aply", "Error fetching query results");
db_query_end(&qp);
evbuffer_free(playlistlist);
return;
goto out_list_free;
}
if (oom)
@ -1529,8 +1513,7 @@ daap_reply_playlists(struct evhttp_request *req, struct evbuffer *evbuf, char **
daap_send_error(req, "aply", "Out of memory");
db_query_end(&qp);
evbuffer_free(playlistlist);
return;
goto out_list_free;
}
/* Add header to evbuf, add playlistlist to evbuf */
@ -1554,6 +1537,19 @@ daap_reply_playlists(struct evhttp_request *req, struct evbuffer *evbuf, char **
}
evhttp_send_reply(req, HTTP_OK, "OK", evbuf);
return;
out_query_free:
free(meta);
if (qp.filter)
free(qp.filter);
out_pl_free:
evbuffer_free(playlist);
out_list_free:
evbuffer_free(playlistlist);
}
static void