[-] Lots of housekeeping thanks to scan-build and input from @acmay

This commit is contained in:
ejurgensen 2016-11-19 23:08:50 +01:00
parent 8525c278ec
commit bdd6bab982
21 changed files with 159 additions and 81 deletions

View File

@ -92,9 +92,7 @@ command_cb_sync(struct commands_base *cmdbase, struct command *cmd)
{
// Command execution finished, execute the bottom half function
if (cmd->ret == 0 && cmd->func_bh)
{
cmdstate = cmd->func_bh(cmd->arg, &cmd->ret);
}
cmd->func_bh(cmd->arg, &cmd->ret);
// Signal the calling thread that the command execution finished
pthread_cond_signal(&cmd->cond);
@ -159,6 +157,7 @@ send_command(struct commands_base *cmdbase, struct command *cmd)
ret = write(cmdbase->command_pipe[1], &cmd, sizeof(cmd));
if (ret != sizeof(cmd))
{
DPRINTF(E_LOG, L_MAIN, "Bad write to command pipe (write incomplete)\n");
return -1;
}
@ -360,7 +359,10 @@ commands_exec_async(struct commands_base *cmdbase, command_function func, void *
ret = send_command(cmdbase, cmd);
if (ret < 0)
{
free(cmd);
return -1;
}
return 0;
}

View File

@ -377,7 +377,7 @@ db_upgrade_v11(sqlite3 *hdl)
else if (count < 0)
return -1;
spkids = (uint64_t *)malloc(count * sizeof(uint64_t));
spkids = calloc(count, sizeof(uint64_t));
if (!spkids)
{
DPRINTF(E_LOG, L_DB, "Out of memory for speaker IDs\n");
@ -1073,7 +1073,6 @@ db_upgrade_v16(sqlite3 *hdl)
}
}
sqlite3_free(errmsg);
sqlite3_finalize(stmt);
return 0;

View File

@ -161,7 +161,7 @@ push_dir(struct stacked_dir **s, char *path, int parent_id)
{
struct stacked_dir *d;
d = (struct stacked_dir *)malloc(sizeof(struct stacked_dir));
d = malloc(sizeof(struct stacked_dir));
if (!d)
{
DPRINTF(E_LOG, L_SCAN, "Could not stack directory %s; out of memory\n", path);
@ -172,6 +172,7 @@ push_dir(struct stacked_dir **s, char *path, int parent_id)
if (!d->path)
{
DPRINTF(E_LOG, L_SCAN, "Could not stack directory %s; out of memory for path\n", path);
free(d);
return -1;
}
@ -1025,13 +1026,15 @@ process_directory(char *path, int parent_id, int flags)
}
ret = snprintf(entry, sizeof(entry), "%s", deref);
free(deref);
if ((ret < 0) || (ret >= sizeof(entry)))
{
DPRINTF(E_LOG, L_SCAN, "Skipping %s, PATH_MAX exceeded\n", deref);
DPRINTF(E_LOG, L_SCAN, "Skipping %s, PATH_MAX exceeded\n", entry);
free(deref);
continue;
}
free(deref);
}
if (S_ISREG(sb.st_mode))

View File

@ -183,15 +183,13 @@ scan_smartpl(char *file, time_t mtime, int dir_id)
pli = db_pl_fetch_bypath(file);
if (!pli)
{
pli = (struct playlist_info *) malloc(sizeof(struct playlist_info));
pli = calloc(1, sizeof(struct playlist_info));
if (!pli)
{
DPRINTF(E_LOG, L_SCAN, "Out of memory\n");
return;
}
memset(pli, 0, sizeof(struct playlist_info));
pli->path = strdup(file);
snprintf(virtual_path, PATH_MAX, "/file:%s", file);
ptr = strrchr(virtual_path, '.');
@ -200,8 +198,6 @@ scan_smartpl(char *file, time_t mtime, int dir_id)
pli->virtual_path = strdup(virtual_path);
pli->type = PL_SMART;
}
else
pl_id = pli->id;
pli->directory_id = dir_id;
@ -216,6 +212,7 @@ scan_smartpl(char *file, time_t mtime, int dir_id)
if (pli->id)
{
pl_id = pli->id;
ret = db_pl_update(pli);
}
else
@ -230,7 +227,7 @@ scan_smartpl(char *file, time_t mtime, int dir_id)
return;
}
DPRINTF(E_INFO, L_SCAN, "Added smart playlist as id %d\n", pl_id);
DPRINTF(E_INFO, L_SCAN, "Added or updated smart playlist as id %d\n", pl_id);
free_pli(pli, 0);

View File

@ -1248,11 +1248,10 @@ httpd_basic_auth(struct evhttp_request *req, char *user, char *passwd, char *rea
{
struct evbuffer *evbuf;
struct evkeyvalq *headers;
char *header;
char header[256];
const char *auth;
char *authuser;
char *authpwd;
int len;
int ret;
headers = evhttp_request_get_input_headers(req);
@ -1317,16 +1316,8 @@ httpd_basic_auth(struct evhttp_request *req, char *user, char *passwd, char *rea
return 0;
need_auth:
len = strlen(realm) + strlen("Basic realm=") + 3;
header = (char *)malloc(len);
if (!header)
{
httpd_send_error(req, HTTP_SERVUNAVAIL, "Internal Server Error");
return -1;
}
ret = snprintf(header, len, "Basic realm=\"%s\"", realm);
if ((ret < 0) || (ret >= len))
ret = snprintf(header, sizeof(header), "Basic realm=\"%s\"", realm);
if ((ret < 0) || (ret >= sizeof(header)))
{
httpd_send_error(req, HTTP_SERVUNAVAIL, "Internal Server Error");
return -1;
@ -1346,7 +1337,6 @@ httpd_basic_auth(struct evhttp_request *req, char *user, char *passwd, char *rea
httpd_send_reply(req, 401, "Unauthorized", evbuf, HTTPD_SEND_NO_GZIP);
free(header);
evbuffer_free(evbuf);
return -1;

View File

@ -785,6 +785,7 @@ find_first_song_id(const char *query)
int id;
int ret;
id = 0;
memset(&qp, 0, sizeof(struct query_params));
/* We only want the id of the first song */
@ -1012,6 +1013,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)
{
@ -1030,8 +1033,6 @@ dacp_reply_cue_play(struct evhttp_request *req, struct evbuffer *evbuf, char **u
}
else
{
player_get_status(&status);
if (status.status != PLAY_STOPPED)
player_playback_stop();
}
@ -1537,7 +1538,6 @@ dacp_reply_playqueuecontents(struct evhttp_request *req, struct evbuffer *evbuf,
DPRINTF(E_LOG, L_DACP, "Invalid span value in playqueue-contents request\n");
}
i = 0;
n = 0; // count of songs in songlist
songlist = evbuffer_new();
if (!songlist)
@ -1548,6 +1548,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.
@ -1577,8 +1579,6 @@ dacp_reply_playqueuecontents(struct evhttp_request *req, struct evbuffer *evbuf,
}
else
{
player_get_status(&status);
queue = player_queue_get_bypos(abs(span));
if (queue)
{

View File

@ -97,6 +97,13 @@ streaming_fail_cb(struct evhttp_connection *evcon, void *arg)
prev = session;
}
if (!session)
{
DPRINTF(E_LOG, L_STREAMING, "Bug! Got a failure callback for an unknown stream\n");
free(this);
return;
}
if (!prev)
streaming_sessions = session->next;
else

View File

@ -575,23 +575,28 @@ lastfm_login(char *path)
kv = keyval_alloc();
if (!kv)
{
free(username);
free(password);
return -1;
ret = -1;
goto out_free_credentials;
}
ret = ( (keyval_add(kv, "api_key", lastfm_api_key) == 0) &&
(keyval_add(kv, "username", username) == 0) &&
(keyval_add(kv, "password", password) == 0) );
free(username);
free(password);
if (!ret)
{
ret = -1;
goto out_free_kv;
}
// Send the login request
ret = request_post("auth.getMobileSession", kv, 1);
out_free_kv:
keyval_clear(kv);
free(kv);
out_free_credentials:
free(username);
free(password);
return ret;
}

View File

@ -498,7 +498,6 @@ main(int argc, char **argv)
ffid = NULL;
mdns_no_rsp = 0;
mdns_no_daap = 0;
mdns_no_mpd = 1; // only announce if mpd protocol support is activated
while ((option = getopt_long(argc, argv, "D:d:c:P:fb:v", option_map, NULL)) != -1)
{
@ -789,6 +788,8 @@ main(int argc, char **argv)
goto mpd_fail;
}
mdns_no_mpd = 0;
#else
mdns_no_mpd = 1;
#endif
/* Start Remote pairing service */

View File

@ -498,12 +498,14 @@ browse_resolve_callback(AvahiServiceResolver *r, AvahiIfIndex intf, AvahiProtoco
DPRINTF(E_DBG, L_MDNS, "Avahi Resolver: resolved service '%s' type '%s' proto %d, host %s\n", name, type, proto, hostname);
rb_data = calloc(1, sizeof(struct mdns_record_browser));
if (! (rb_data && (rb_data->name = strdup(name)) && (rb_data->domain = strdup(domain))) )
if (!rb_data)
{
DPRINTF(E_LOG, L_MDNS, "Out of memory\n");
goto out_free_resolver;
}
rb_data->name = strdup(name);
rb_data->domain = strdup(domain);
rb_data->mb = (struct mdns_browser *)userdata;
rb_data->port = port;

View File

@ -430,7 +430,7 @@ keyval_sort(struct keyval *kv)
struct onekeyval *okv;
struct onekeyval *sokv;
if (!kv)
if (!kv || !kv->head)
return;
head = kv->head;

View File

@ -4268,6 +4268,7 @@ mpd_read_cb(struct bufferevent *bev, void *ctx)
listtype = COMMAND_LIST_NONE;
ncmd = 0;
ret = -1;
while ((line = evbuffer_readln(input, NULL, EVBUFFER_EOL_ANY)))
{

View File

@ -170,10 +170,17 @@ alsa_session_make(struct output_device *device, output_status_cb cb)
struct alsa_session *as;
os = calloc(1, sizeof(struct output_session));
as = calloc(1, sizeof(struct alsa_session));
if (!os || !as)
if (!os)
{
DPRINTF(E_LOG, L_LAUDIO, "Out of memory for ALSA session\n");
DPRINTF(E_LOG, L_LAUDIO, "Out of memory for ALSA session (os)\n");
return NULL;
}
as = calloc(1, sizeof(struct alsa_session));
if (!as)
{
DPRINTF(E_LOG, L_LAUDIO, "Out of memory for ALSA session (as)\n");
free(os);
return NULL;
}

View File

@ -1323,10 +1323,17 @@ cast_session_make(struct output_device *device, int family, output_status_cb cb)
}
os = calloc(1, sizeof(struct output_session));
cs = calloc(1, sizeof(struct cast_session));
if (!os || !cs)
if (!os)
{
DPRINTF(E_LOG, L_CAST, "Out of memory for TLS session\n");
DPRINTF(E_LOG, L_CAST, "Out of memory (os)\n");
return NULL;
}
cs = calloc(1, sizeof(struct cast_session));
if (!cs)
{
DPRINTF(E_LOG, L_CAST, "Out of memory (cs)\n");
free(os);
return NULL;
}

View File

@ -91,10 +91,17 @@ dummy_session_make(struct output_device *device, output_status_cb cb)
struct dummy_session *ds;
os = calloc(1, sizeof(struct output_session));
ds = calloc(1, sizeof(struct dummy_session));
if (!os || !ds)
if (!os)
{
DPRINTF(E_LOG, L_LAUDIO, "Out of memory for dummy session\n");
DPRINTF(E_LOG, L_LAUDIO, "Out of memory for dummy session (os)\n");
return NULL;
}
ds = calloc(1, sizeof(struct dummy_session));
if (!ds)
{
DPRINTF(E_LOG, L_LAUDIO, "Out of memory for dummy session (as)\n");
free(os);
return NULL;
}

View File

@ -221,10 +221,17 @@ fifo_session_make(struct output_device *device, output_status_cb cb)
struct fifo_session *fifo_session;
output_session = calloc(1, sizeof(struct output_session));
fifo_session = calloc(1, sizeof(struct fifo_session));
if (!output_session || !fifo_session)
if (!output_session)
{
DPRINTF(E_LOG, L_FIFO, "Out of memory for fifo session\n");
DPRINTF(E_LOG, L_FIFO, "Out of memory (os)\n");
return NULL;
}
fifo_session = calloc(1, sizeof(struct fifo_session));
if (!fifo_session)
{
DPRINTF(E_LOG, L_FIFO, "Out of memory (fs)\n");
free(output_session);
return NULL;
}

View File

@ -146,10 +146,17 @@ pulse_session_make(struct output_device *device, output_status_cb cb)
struct pulse_session *ps;
os = calloc(1, sizeof(struct output_session));
ps = calloc(1, sizeof(struct pulse_session));
if (!os || !ps)
if (!os)
{
DPRINTF(E_LOG, L_LAUDIO, "Out of memory for Pulseaudio session\n");
DPRINTF(E_LOG, L_LAUDIO, "Out of memory (os)\n");
return NULL;
}
ps = calloc(1, sizeof(struct pulse_session));
if (!ps)
{
DPRINTF(E_LOG, L_LAUDIO, "Out of memory (ps)\n");
free(os);
return NULL;
}

View File

@ -1885,10 +1885,17 @@ raop_session_make(struct output_device *rd, int family, output_status_cb cb)
}
os = calloc(1, sizeof(struct output_session));
rs = calloc(1, sizeof(struct raop_session));
if (!os || !rs)
if (!os)
{
DPRINTF(E_LOG, L_RAOP, "Out of memory for RAOP session\n");
DPRINTF(E_LOG, L_RAOP, "Out of memory (os)\n");
return NULL;
}
rs = calloc(1, sizeof(struct raop_session));
if (!rs)
{
DPRINTF(E_LOG, L_RAOP, "Out of memory (rs)\n");
free(os);
return NULL;
}
@ -4034,10 +4041,18 @@ raop_device_cb(const char *name, const char *type, const char *domain, const cha
DPRINTF(E_DBG, L_RAOP, "Event for AirPlay device %s (port %d, id %" PRIx64 ")\n", at_name, port, id);
rd = calloc(1, sizeof(struct output_device));
re = calloc(1, sizeof(struct raop_extra));
if (!rd || !re)
if (!rd)
{
DPRINTF(E_LOG, L_RAOP, "Out of memory for new AirPlay device\n");
DPRINTF(E_LOG, L_RAOP, "Out of memory (rd)\n");
return;
}
re = calloc(1, sizeof(struct raop_extra));
if (!re)
{
DPRINTF(E_LOG, L_RAOP, "Out of memory (re)\n");
free(rd);
return;
}

View File

@ -967,7 +967,12 @@ source_new(struct queue_item *item)
{
struct player_source *ps;
ps = (struct player_source *)calloc(1, sizeof(struct player_source));
ps = calloc(1, sizeof(struct player_source));
if (!ps)
{
DPRINTF(E_LOG, L_PLAYER, "Out of memory (ps)\n");
return NULL;
}
ps->id = queueitem_id(item);
ps->item_id = queueitem_item_id(item);
@ -1027,6 +1032,8 @@ source_pause(uint64_t pos)
int ret;
ps_playing = source_now_playing();
if (!ps_playing)
return -1;
if (cur_streaming)
{
@ -1187,11 +1194,14 @@ source_open(struct queue_item *qii, uint64_t start_pos, int seek)
DPRINTF(E_INFO, L_PLAYER, "Opening '%s' (%s)\n", mfi->title, mfi->path);
ps = source_new(qii);
if (!ps)
return -1;
ret = stream_setup(ps, mfi);
if (ret < 0)
{
DPRINTF(E_LOG, L_PLAYER, "Failed to open '%s' (%s)\n", mfi->title, mfi->path);
free(ps);
free_mfi(mfi, 0);
return -1;
}

View File

@ -922,7 +922,6 @@ open_filter(struct filter_ctx *filter_ctx, AVCodecContext *dec_ctx, AVCodecConte
if (!buffersrc || !buffersink)
{
DPRINTF(E_LOG, L_XCODE, "Filtering source or sink element not found\n");
ret = AVERROR_UNKNOWN;
goto out_fail;
}
@ -1339,6 +1338,7 @@ transcode_decode_setup_raw(void)
if (!ctx->ifmt_ctx)
{
DPRINTF(E_LOG, L_XCODE, "Out of memory for decode format ctx\n");
free(ctx);
return NULL;
}
@ -1348,6 +1348,8 @@ transcode_decode_setup_raw(void)
if (!ctx->audio_stream)
{
DPRINTF(E_LOG, L_XCODE, "Could not create stream with PCM16 decoder\n");
avformat_free_context(ctx->ifmt_ctx);
free(ctx);
return NULL;
}
@ -1524,7 +1526,6 @@ transcode_decode(struct decoded_frame **decoded, struct decode_ctx *ctx)
// with empty input until no more frames are returned
DPRINTF(E_DBG, L_XCODE, "Could not read packet, will flush decoders\n");
used = 1;
got_frame = flush_decoder(frame, &in_stream, &stream_index, ctx);
if (got_frame)
break;
@ -1573,9 +1574,11 @@ transcode_decode(struct decoded_frame **decoded, struct decode_ctx *ctx)
}
while (!got_frame);
if (got_frame > 0)
{
// Return the decoded frame and stream index
*decoded = malloc(sizeof(struct decoded_frame));
if (!*decoded)
if (!(*decoded))
{
DPRINTF(E_LOG, L_XCODE, "Out of memory for decoded result\n");
@ -1585,6 +1588,7 @@ transcode_decode(struct decoded_frame **decoded, struct decode_ctx *ctx)
(*decoded)->frame = frame;
(*decoded)->stream_index = stream_index;
}
return got_frame;
}
@ -1659,10 +1663,17 @@ transcode_raw2frame(uint8_t *data, size_t size)
int ret;
decoded = malloc(sizeof(struct decoded_frame));
frame = av_frame_alloc();
if (!decoded || !frame)
if (!decoded)
{
DPRINTF(E_LOG, L_XCODE, "Out of memory for decoded struct or frame\n");
DPRINTF(E_LOG, L_XCODE, "Out of memory for decoded struct\n");
return NULL;
}
frame = av_frame_alloc();
if (!frame)
{
DPRINTF(E_LOG, L_XCODE, "Out of memory for frame\n");
free(decoded);
return NULL;
}
@ -1682,6 +1693,7 @@ transcode_raw2frame(uint8_t *data, size_t size)
if (ret < 0)
{
DPRINTF(E_LOG, L_XCODE, "Error filling frame with rawbuf: %s\n", err2str(ret));
transcode_decoded_free(decoded);
return NULL;
}

View File

@ -142,19 +142,18 @@ worker_execute(void (*cb)(void *), void *cb_arg, size_t arg_size, int delay)
DPRINTF(E_DBG, L_MAIN, "Got worker execute request\n");
cmdarg = (struct worker_arg *)malloc(sizeof(struct worker_arg));
cmdarg = calloc(1, sizeof(struct worker_arg));
if (!cmdarg)
{
DPRINTF(E_LOG, L_MAIN, "Could not allocate worker_arg\n");
return;
}
memset(cmdarg, 0, sizeof(struct worker_arg));
argcpy = malloc(arg_size);
if (!argcpy)
{
DPRINTF(E_LOG, L_MAIN, "Out of memory\n");
free(cmdarg);
return;
}