From dfacef3019e560159601c80745f2b88919f65d27 Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Mon, 11 Nov 2013 20:55:09 +0100 Subject: fixed few errors reported by cppcheck (thanks to Pavel Roschin) --- dsppreset.c | 2 +- plugins/ao/plugin.c | 1 + plugins/dumb/dumb-kode54/src/it/readptm.c | 3 +++ plugins/dumb/dumb-kode54/src/it/readxm.c | 1 + plugins/mms/libmms/uri.c | 9 +++++++-- plugins/shellexec/shellexec.c | 2 +- .../libsidplay/src/mos6510/cycle_based/mos6510c.i | 11 ++++++----- plugins/vtx/vtxfile.c | 15 +++++++++------ plugins/wildmidi/src/wildmidi_lib.c | 11 ++++++++--- streamer.c | 2 +- 10 files changed, 38 insertions(+), 19 deletions(-) diff --git a/dsppreset.c b/dsppreset.c index 6540ed22..70d5d698 100644 --- a/dsppreset.c +++ b/dsppreset.c @@ -56,7 +56,7 @@ dsp_preset_load (const char *fname, ddb_dsp_context_t **head) { char temp[100]; for (;;) { // plugin { - int err = fscanf (fp, "%100s {\n", temp); + int err = fscanf (fp, "%99s {\n", temp); if (err == EOF) { break; } diff --git a/plugins/ao/plugin.c b/plugins/ao/plugin.c index d997c759..7964c311 100644 --- a/plugins/ao/plugin.c +++ b/plugins/ao/plugin.c @@ -228,6 +228,7 @@ aoplug_insert (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname) { if (deadbeef->fread(buffer, 1, size, fp) != size) { deadbeef->fclose (fp); + free (buffer); fprintf(stderr, "psf: file read error: %s\n", fname); return NULL; } diff --git a/plugins/dumb/dumb-kode54/src/it/readptm.c b/plugins/dumb/dumb-kode54/src/it/readptm.c index cae73edf..7e9801fe 100644 --- a/plugins/dumb/dumb-kode54/src/it/readptm.c +++ b/plugins/dumb/dumb-kode54/src/it/readptm.c @@ -457,6 +457,7 @@ static DUMB_IT_SIGDATA *it_ptm_load_sigdata(DUMBFILE *f) if (it_seek(f, 352)) { _dumb_it_unload_sigdata(sigdata); + free (component); return NULL; } @@ -468,12 +469,14 @@ static DUMB_IT_SIGDATA *it_ptm_load_sigdata(DUMBFILE *f) } if (it_seek(f, 608)) { + free (component); _dumb_it_unload_sigdata(sigdata); return NULL; } for (n = 0; n < sigdata->n_samples; n++) { if (it_ptm_read_sample_header(&sigdata->sample[n], &component[n_components].offset, f)) { + free (component); _dumb_it_unload_sigdata(sigdata); return NULL; } diff --git a/plugins/dumb/dumb-kode54/src/it/readxm.c b/plugins/dumb/dumb-kode54/src/it/readxm.c index 7ceed801..74bf02dd 100644 --- a/plugins/dumb/dumb-kode54/src/it/readxm.c +++ b/plugins/dumb/dumb-kode54/src/it/readxm.c @@ -907,6 +907,7 @@ static DUMB_IT_SIGDATA *it_xm_load_sigdata(DUMBFILE *f, int * version) sigdata->instrument = malloc(sigdata->n_instruments * sizeof(*sigdata->instrument)); if (!sigdata->instrument) { + free (roguebytes); _dumb_it_unload_sigdata(sigdata); return NULL; } diff --git a/plugins/mms/libmms/uri.c b/plugins/mms/libmms/uri.c index 111ca128..38bb8dba 100644 --- a/plugins/mms/libmms/uri.c +++ b/plugins/mms/libmms/uri.c @@ -144,11 +144,16 @@ static int split_user_passwd(const char* in, char** user, char** passwd) *((*passwd)++) = '\0'; // don't you love C? :) *user = strdup(tmp); - if(!*user) + if(!*user) { + free (tmp); return 0; + } *passwd = strdup(*passwd); - if(!*passwd) + if(!*passwd) { + free (tmp); + free (*user); return 0; + } free(tmp); return 1; diff --git a/plugins/shellexec/shellexec.c b/plugins/shellexec/shellexec.c index 56ceb970..99bb4715 100644 --- a/plugins/shellexec/shellexec.c +++ b/plugins/shellexec/shellexec.c @@ -106,7 +106,7 @@ shx_callback (Shx_action_t *action, int ctx) deadbeef->pl_lock (); ddb_playlist_t *plt = deadbeef->plt_get_curr (); if (plt) { - DB_playItem_t **items; + DB_playItem_t **items = NULL; int items_count = deadbeef->plt_getselcount (plt); if (0 < items_count) { items = malloc (sizeof (DB_playItem_t *) * items_count); diff --git a/plugins/sid/sidplay-libs/libsidplay/src/mos6510/cycle_based/mos6510c.i b/plugins/sid/sidplay-libs/libsidplay/src/mos6510/cycle_based/mos6510c.i index c1aa0559..646da760 100644 --- a/plugins/sid/sidplay-libs/libsidplay/src/mos6510/cycle_based/mos6510c.i +++ b/plugins/sid/sidplay-libs/libsidplay/src/mos6510/cycle_based/mos6510c.i @@ -131,6 +131,7 @@ const char _sidtune_CHRtab[256] = // CHR$ conversion table (0x01 = no output) */ #include "config.h" +#include #ifdef HAVE_EXCEPTIONS # include @@ -2559,9 +2560,9 @@ void MOS6510::reset (void) // Module Credits // void MOS6510::credits (char *sbuffer) { // Copy credits to buffer - sprintf (sbuffer, "%sModule : MOS6510 Cycle Exact Emulation\n", sbuffer); - sprintf (sbuffer, "%sWritten By : %s\n", sbuffer, MOS6510_AUTHOR); - sprintf (sbuffer, "%sVersion : %s\n", sbuffer, MOS6510_VERSION); - sprintf (sbuffer, "%sReleased : %s\n", sbuffer, MOS6510_DATE); - sprintf (sbuffer, "%sEmail : %s\n", sbuffer, MOS6510_EMAIL); + strcat (sbuffer, "Module : MOS6510 Cycle Exact Emulation\n" + "Written By : " MOS6510_AUTHOR "\n" + "Version : " MOS6510_VERSION "\n" + "Released : " MOS6510_DATE "\n" + "Email : " MOS6510_EMAIL "\n"); } diff --git a/plugins/vtx/vtxfile.c b/plugins/vtx/vtxfile.c index 9dbeb9f7..ff9914e6 100644 --- a/plugins/vtx/vtxfile.c +++ b/plugins/vtx/vtxfile.c @@ -192,12 +192,15 @@ void ayemu_vtx_free(ayemu_vtx_t *vtx) { #define FREE_PTR(x) if (x) { free(x); x = NULL; } - FREE_PTR(vtx->title); - FREE_PTR(vtx->author); - FREE_PTR(vtx->from); - FREE_PTR(vtx->tracker); - FREE_PTR(vtx->comment); - FREE_PTR(vtx->regdata); + if (vtx) { + FREE_PTR(vtx->title); + FREE_PTR(vtx->author); + FREE_PTR(vtx->from); + FREE_PTR(vtx->tracker); + FREE_PTR(vtx->comment); + FREE_PTR(vtx->regdata); + free (vtx); + } } diff --git a/plugins/wildmidi/src/wildmidi_lib.c b/plugins/wildmidi/src/wildmidi_lib.c index 892ea3c4..26bf72ac 100644 --- a/plugins/wildmidi/src/wildmidi_lib.c +++ b/plugins/wildmidi/src/wildmidi_lib.c @@ -748,15 +748,19 @@ WM_LoadConfig (const char *config_file, const char *top_config_dir) { char * new_config = NULL; struct _patch * tmp_patch; + if ((config_buffer = WM_BufferFile(config_file, &config_size)) == NULL) { + return -1; + } + if (top_config_dir) { config_dir = strdup (top_config_dir); } - if ((config_buffer = WM_BufferFile(config_file, &config_size)) == NULL) { - return -1; - } if (config_buffer == NULL) { WM_FreePatches(); + if (config_dir) { + free (config_dir); + } return -1; } @@ -3496,6 +3500,7 @@ WM_ParseNewMidi(unsigned char *mididata, unsigned long int midisize ) { first_handle = malloc(sizeof(struct _hndl)); if (first_handle == NULL) { WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM," to parse midi data", errno); + free (tmp_trackdata); free(mdi->data); free(mdi); return NULL; diff --git a/streamer.c b/streamer.c index d09ef738..f6d966b8 100644 --- a/streamer.c +++ b/streamer.c @@ -1663,7 +1663,7 @@ streamer_dsp_chain_load (const char *fname) { for (;;) { // plugin enabled { int enabled = 0; - int err = fscanf (fp, "%100s %d {\n", temp, &enabled); + int err = fscanf (fp, "%99s %d {\n", temp, &enabled); if (err == EOF) { break; } -- cgit v1.2.3