diff --git a/src/common/fd.cc b/src/common/fd.cc index 547e0f8e27b..1154e05d580 100644 --- a/src/common/fd.cc +++ b/src/common/fd.cc @@ -41,7 +41,7 @@ void dump_open_fds(CephContext *cct) char path[PATH_MAX]; snprintf(path, sizeof(path), "%s/%s", fn, de.d_name); char target[PATH_MAX]; - ssize_t r = readlink(path, target, sizeof(target)); + ssize_t r = readlink(path, target, sizeof(target) - 1); if (r < 0) { r = -errno; lderr(cct) << "dump_open_fds unable to readlink " << path << ": " << cpp_strerror(r) << dendl; diff --git a/src/libradosstriper/RadosStriperImpl.cc b/src/libradosstriper/RadosStriperImpl.cc index 559a7780bab..2460999eb31 100644 --- a/src/libradosstriper/RadosStriperImpl.cc +++ b/src/libradosstriper/RadosStriperImpl.cc @@ -588,7 +588,7 @@ int libradosstriper::RadosStriperImpl::remove(const std::string& soid) } // return return rcr; - } catch (ErrorCode e) { + } catch (ErrorCode &e) { // errror caught when trying to take the exclusive lock return e.m_code; } @@ -600,7 +600,7 @@ int libradosstriper::RadosStriperImpl::trunc(const std::string& soid, uint64_t s std::string firstObjOid = getObjectId(soid, 0); try { RadosExclusiveLock lock(&m_ioCtx, firstObjOid); - } catch (ErrorCode e) { + } catch (ErrorCode &e) { return e.m_code; } // load layout and size diff --git a/src/mds/MDCache.h b/src/mds/MDCache.h index bd823429f5f..17b038ebb48 100644 --- a/src/mds/MDCache.h +++ b/src/mds/MDCache.h @@ -325,7 +325,7 @@ protected: bool safe; bool committing; bool recovering; - umaster() : committing(false), recovering(false) {} + umaster() : ls(NULL), safe(false), committing(false), recovering(false) {} }; map uncommitted_masters; // master: req -> slave set diff --git a/src/mount/mount.ceph.c b/src/mount/mount.ceph.c index 9d4e33b49ef..e34cbd05014 100644 --- a/src/mount/mount.ceph.c +++ b/src/mount/mount.ceph.c @@ -154,6 +154,7 @@ static char *parse_options(const char *data, int *filesys_flags) } else if (strncmp(data, "secretfile", 10) == 0) { if (!value || !*value) { printf("keyword secretfile found, but no secret file specified\n"); + free(saw_name); return NULL; } @@ -186,9 +187,8 @@ static char *parse_options(const char *data, int *filesys_flags) } /* take a copy of the name, to be used for - naming the keys that we add to kernel; - ignore memleak as mount.ceph is - short-lived */ + naming the keys that we add to kernel; */ + free(saw_name); saw_name = strdup(value); if (!saw_name) { printf("out of memory.\n"); @@ -229,6 +229,7 @@ static char *parse_options(const char *data, int *filesys_flags) char secret_option[MAX_SECRET_OPTION_LEN]; ret = get_secret_option(saw_secret, name, secret_option, sizeof(secret_option)); if (ret < 0) { + free(saw_name); return NULL; } else { if (pos) { @@ -238,6 +239,7 @@ static char *parse_options(const char *data, int *filesys_flags) } } + free(saw_name); if (!out) return strdup(EMPTY_STRING); return out; diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index ac88c9817c3..be864eba704 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -1994,7 +1994,7 @@ public: } void chain_cb(const string& key, void *data) { - T *entry = (T *)data; + T *entry = static_cast(data); RWLock::WLocker wl(lock); entries[key] = *entry; } diff --git a/src/test/libcephfs/test.cc b/src/test/libcephfs/test.cc index e64e8311e4e..9204150914e 100644 --- a/src/test/libcephfs/test.cc +++ b/src/test/libcephfs/test.cc @@ -132,7 +132,6 @@ TEST(LibCephFS, ReleaseMounted) { ASSERT_EQ(0, ceph_conf_read_file(cmount, NULL)); ASSERT_EQ(0, ceph_mount(cmount, "/")); ASSERT_EQ(-EISCONN, ceph_release(cmount)); - ceph_shutdown(cmount); } TEST(LibCephFS, UnmountRelease) { diff --git a/src/test/libradosstriper/striping.cc b/src/test/libradosstriper/striping.cc index 3fe320ca02b..c7b6ce5813f 100644 --- a/src/test/libradosstriper/striping.cc +++ b/src/test/libradosstriper/striping.cc @@ -137,7 +137,8 @@ protected: // check we do not have an extra object behind uint64_t rados_size; time_t mtime; - ASSERT_EQ(-ENOENT, ioctx.stat(getObjName(soid, nb_objects), &rados_size, &mtime)); + std::string oid = getObjName(soid, nb_objects); + ASSERT_EQ(-ENOENT, ioctx.stat(oid, &rados_size, &mtime)); } }; diff --git a/src/test/objectstore/store_test.cc b/src/test/objectstore/store_test.cc index 4ba6623a3fc..94ab050366d 100644 --- a/src/test/objectstore/store_test.cc +++ b/src/test/objectstore/store_test.cc @@ -596,7 +596,7 @@ public: map::iterator it = contents[obj].attrs.begin(); while (retry) { retry--; - it++; + ++it; } bufferlist bl; @@ -624,7 +624,7 @@ public: map::iterator it = contents[obj].attrs.begin(); while (retry) { retry--; - it++; + ++it; } available_objects.erase(obj); diff --git a/src/tools/scratchtool.c b/src/tools/scratchtool.c index eecafb4e305..9f717903ce2 100644 --- a/src/tools/scratchtool.c +++ b/src/tools/scratchtool.c @@ -56,24 +56,24 @@ static int do_rados_getxattrs(rados_ioctx_t io_ctx, const char *oid, const char **exkeys, const char **exvals) { rados_xattrs_iter_t iter; - int nval = 0, i, nfound = 0, ret = 0; + int nval = 0, i, nfound = 0, r = 0, ret = 1; for (i = 0; exvals[i]; ++i) { ++nval; } - ret = rados_getxattrs(io_ctx, oid, &iter); - if (ret) { - printf("rados_getxattrs(%s) failed with error %d\n", oid, ret); + r = rados_getxattrs(io_ctx, oid, &iter); + if (r) { + printf("rados_getxattrs(%s) failed with error %d\n", oid, r); return 1; } while (1) { size_t len; const char *key, *val; - ret = rados_getxattrs_next(iter, &key, &val, &len); - if (ret) { + r = rados_getxattrs_next(iter, &key, &val, &len); + if (r) { printf("rados_getxattrs(%s): rados_getxattrs_next " - "returned error %d\n", oid, ret); - return 1; + "returned error %d\n", oid, r); + goto out_err; } if (!key) break; @@ -87,17 +87,20 @@ static int do_rados_getxattrs(rados_ioctx_t io_ctx, const char *oid, printf("rados_getxattrs(%s): got key %s, but the " "value was %s rather than %s.\n", oid, key, val, exvals[i]); - return 1; + goto out_err; } } if (nfound != nval) { printf("rados_getxattrs(%s): only found %d extended attributes. " "Expected %d\n", oid, nfound, nval); - return 1; + goto out_err; } - rados_getxattrs_end(iter); + ret = 0; printf("rados_getxattrs(%s)\n", oid); - return 0; + +out_err: + rados_getxattrs_end(iter); + return ret; } static int testrados(void) @@ -159,6 +162,10 @@ static int testrados(void) rados_ioctx_t io_ctx; r = rados_ioctx_create(cl, "foo", &io_ctx); + if (r < 0) { + printf("error creating ioctx\n"); + goto out_err; + } printf("rados_ioctx_create = %d, io_ctx = %p\n", r, io_ctx); /* list all pools */ @@ -170,7 +177,7 @@ static int testrados(void) if (r != buf_sz) { printf("buffer size mismatch: got %d the first time, but %d " "the second.\n", buf_sz, r); - goto out_err; + goto out_err_cleanup; } const char *b = buf; printf("begin pools.\n"); @@ -220,21 +227,21 @@ static int testrados(void) /* attrs */ if (do_rados_setxattr(io_ctx, oid, "b", "2")) - goto out_err; + goto out_err_cleanup; if (do_rados_setxattr(io_ctx, oid, "a", "1")) - goto out_err; + goto out_err_cleanup; if (do_rados_setxattr(io_ctx, oid, "c", "3")) - goto out_err; + goto out_err_cleanup; if (do_rados_getxattr(io_ctx, oid, "a", "1")) - goto out_err; + goto out_err_cleanup; if (do_rados_getxattr(io_ctx, oid, "b", "2")) - goto out_err; + goto out_err_cleanup; if (do_rados_getxattr(io_ctx, oid, "c", "3")) - goto out_err; + goto out_err_cleanup; const char *exkeys[] = { "a", "b", "c", NULL }; const char *exvals[] = { "1", "2", "3", NULL }; if (do_rados_getxattrs(io_ctx, oid, exkeys, exvals)) - goto out_err; + goto out_err_cleanup; uint64_t size; time_t mtime; @@ -292,14 +299,15 @@ static int testrados(void) r = rados_ioctx_pool_stat(io_ctx, &st); printf("rados_stat_pool = %d, %lld KB, %lld objects\n", r, (long long)st.num_kb, (long long)st.num_objects); + ret = 0; + +out_err_cleanup: /* delete a pool */ - printf("rados_delete_pool = %d\n", r); rados_ioctx_destroy(io_ctx); r = rados_pool_delete(cl, "foo"); - printf("rados_ioctx_pool_delete = %d\n", r); + printf("rados_delete_pool = %d\n", r); - ret = 0; out_err: rados_shutdown(cl); return ret;