From dacbb2f22fc38739ffc401122e26c9cf9a8d681f Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 20 Apr 2014 10:02:54 +0200 Subject: [PATCH] Fixed some warnings reported by clang. --- bin/xbps-checkvers/main.c | 2 +- bin/xbps-install/transaction.c | 2 +- bin/xbps-rindex/index-add.c | 12 +++++++++--- bin/xbps-rindex/index-clean.c | 4 ++-- bin/xbps-rindex/sem.c | 2 ++ bin/xbps-rindex/sign.c | 12 +++++++----- lib/initend.c | 1 - lib/pubkey2fp.c | 2 +- 8 files changed, 23 insertions(+), 14 deletions(-) diff --git a/bin/xbps-checkvers/main.c b/bin/xbps-checkvers/main.c index 1359dbcc..711378c4 100644 --- a/bin/xbps-checkvers/main.c +++ b/bin/xbps-checkvers/main.c @@ -275,7 +275,7 @@ rcv_load_file(rcv_t *rcv, const char *fname) static char * rcv_refs(rcv_t *rcv, const char *s, size_t len) { - map_item_t item = map_new_item(); + map_item_t item; size_t i = 0, j = 0, k = 0, count = len*3; char *ref = calloc(count, sizeof(char)); char *buf = calloc(count, sizeof(char)); diff --git a/bin/xbps-install/transaction.c b/bin/xbps-install/transaction.c index 076ae9c8..453bb13b 100644 --- a/bin/xbps-install/transaction.c +++ b/bin/xbps-install/transaction.c @@ -283,7 +283,7 @@ exec_transaction(struct xbps_handle *xhp, int maxcols, bool yes, bool drun) } xbps_dbg_printf(xhp, "Empty transaction dictionary: %s\n", strerror(errno)); - return rv; + goto out; } xbps_dbg_printf(xhp, "Dictionary before transaction happens:\n"); xbps_dbg_printf_append(xhp, "%s", diff --git a/bin/xbps-rindex/index-add.c b/bin/xbps-rindex/index-add.c index 35647a79..0a65d5aa 100644 --- a/bin/xbps-rindex/index-add.c +++ b/bin/xbps-rindex/index-add.c @@ -47,7 +47,8 @@ index_add(struct xbps_handle *xhp, int argc, char **argv, bool force) struct xbps_repo *repo; struct stat st; const char *arch; - char *sha256, *pkgver, *opkgver, *oarch, *pkgname, *tmprepodir, *repodir; + char *sha256, *pkgver, *opkgver, *oarch, *pkgname; + char *tmprepodir = NULL, *repodir = NULL; int rv = 0, ret = 0; bool flush = false, found = false; @@ -256,7 +257,7 @@ index_add(struct xbps_handle *xhp, int argc, char **argv, bool force) if (!repodata_flush(xhp, repodir, idx, idxfiles, idxmeta)) { fprintf(stderr, "%s: failed to write repodata: %s\n", _XBPS_RINDEX, strerror(errno)); - return -1; + goto out; } } printf("index: %u packages registered.\n", xbps_dictionary_count(idx)); @@ -264,6 +265,11 @@ index_add(struct xbps_handle *xhp, int argc, char **argv, bool force) out: index_unlock(il); - + if (tmprepodir) { + free(tmprepodir); + } + if (repodir) { + free(repodir); + } return rv; } diff --git a/bin/xbps-rindex/index-clean.c b/bin/xbps-rindex/index-clean.c index 39a15122..dd5b892c 100644 --- a/bin/xbps-rindex/index-clean.c +++ b/bin/xbps-rindex/index-clean.c @@ -160,7 +160,7 @@ index_clean(struct xbps_handle *xhp, const char *repodir) pthread_mutex_init(&cbd.mtx, NULL); allkeys = xbps_dictionary_all_keys(idx); - rv = xbps_array_foreach_cb_multi(xhp, allkeys, idx, idx_cleaner_cb, &cbd); + (void)xbps_array_foreach_cb_multi(xhp, allkeys, idx, idx_cleaner_cb, &cbd); for (unsigned int x = 0; x < xbps_array_count(cbd.result); x++) { xbps_array_get_cstring(cbd.result, x, &keyname); printf("index-files: removed entry %s\n", keyname); @@ -180,7 +180,7 @@ index_clean(struct xbps_handle *xhp, const char *repodir) cbd.idx = idx; cbd.result = xbps_array_create(); allkeys = xbps_dictionary_all_keys(idxfiles); - rv = xbps_array_foreach_cb_multi(xhp, allkeys, idxfiles, idxfiles_cleaner_cb, &cbd); + (void)xbps_array_foreach_cb_multi(xhp, allkeys, idxfiles, idxfiles_cleaner_cb, &cbd); for (unsigned int x = 0; x < xbps_array_count(cbd.result); x++) { xbps_array_get_cstring(cbd.result, x, &keyname); printf("index-files: removed entry %s\n", keyname); diff --git a/bin/xbps-rindex/sem.c b/bin/xbps-rindex/sem.c index 8cdfa671..736ad0ce 100644 --- a/bin/xbps-rindex/sem.c +++ b/bin/xbps-rindex/sem.c @@ -56,11 +56,13 @@ index_lock(struct xbps_handle *xhp) if (il->sem == SEM_FAILED) { fprintf(stderr, "%s: failed to create/open named " "semaphore: %s\n", _XBPS_RINDEX, strerror(errno)); + free(il); return NULL; } if (sem_wait(il->sem) == -1) { fprintf(stderr, "%s: failed to lock named semaphore: %s\n", _XBPS_RINDEX, strerror(errno)); + free(il); return NULL; } diff --git a/bin/xbps-rindex/sign.c b/bin/xbps-rindex/sign.c index b6928f4c..0e713d4d 100644 --- a/bin/xbps-rindex/sign.c +++ b/bin/xbps-rindex/sign.c @@ -235,6 +235,7 @@ sign_repo(struct xbps_handle *xhp, const char *repodir, binpkg_sig_fd = creat(binpkg_sig, 0644); if (binpkg_sig_fd == -1) { fprintf(stderr, "failed to create %s: %s\n", binpkg_sig, strerror(errno)); + free(sig); free(binpkg_sig); continue; } @@ -248,7 +249,6 @@ sign_repo(struct xbps_handle *xhp, const char *repodir, free(sig); free(binpkg_sig); close(binpkg_sig_fd); - binpkg_fd = binpkg_sig_fd = -1; printf("signed successfully %s\n", pkgver); } xbps_object_iterator_release(iter); @@ -290,8 +290,7 @@ sign_repo(struct xbps_handle *xhp, const char *repodir, if (!repodata_flush(xhp, repodir, repo->idx, repo->idxfiles, meta)) { fprintf(stderr, "failed to write repodata: %s\n", strerror(errno)); - RSA_free(rsa); - return -1; + goto out; } printf("Signed repository (%u package%s)\n", xbps_dictionary_count(repo->idx), @@ -300,12 +299,15 @@ sign_repo(struct xbps_handle *xhp, const char *repodir, out: index_unlock(il); + if (defprivkey) { + free(defprivkey); + } if (rsa) { RSA_free(rsa); rsa = NULL; } - if (repo) + if (repo) { xbps_repo_close(repo); - + } return rv ? -1 : 0; } diff --git a/lib/initend.c b/lib/initend.c index 8d32502d..917c1ca4 100644 --- a/lib/initend.c +++ b/lib/initend.c @@ -280,7 +280,6 @@ xbps_init(struct xbps_handle *xhp) xbps_dbg_printf(xhp, "failed to read configuration file %s: %s\n", xhp->conffile, strerror(rv)); xbps_dbg_printf(xhp, "Using built-in defaults\n"); - rv = 0; } /* Set rootdir */ if (xhp->rootdir[0] == '\0') { diff --git a/lib/pubkey2fp.c b/lib/pubkey2fp.c index 89af9cc1..36cfa64a 100644 --- a/lib/pubkey2fp.c +++ b/lib/pubkey2fp.c @@ -124,7 +124,7 @@ xbps_pubkey2fp(struct xbps_handle *xhp, xbps_data_t pubkey) memcpy(pEncoding, pSshHeader, 11); index = SshEncodeBuffer(&pEncoding[11], eLen, eBytes); - index = SshEncodeBuffer(&pEncoding[11 + index], nLen, nBytes); + (void)SshEncodeBuffer(&pEncoding[11 + index], nLen, nBytes); /* * Compute the RSA fingerprint (MD5).