Skip to content

Commit

Permalink
Merge pull request ceph#1337 from ceph/wip-fix-coverity-20140228
Browse files Browse the repository at this point in the history
Fix different issues found by Coverity

Reviewed-by: Sage Weil <[email protected]>
  • Loading branch information
Sage Weil committed Mar 2, 2014
2 parents 4bf32c6 + 1a4657a commit 32a4e90
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/common/histogram.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ struct pow2_hist_t { //
lower_sum += h[i];
total += h[i];
}
*lower = lower_sum * 1000000 / total;
*upper = upper_sum * 1000000 / total;
if (total > 0) {
*lower = lower_sum * 1000000 / total;
*upper = upper_sum * 1000000 / total;
}
return 0;
}

Expand Down
9 changes: 7 additions & 2 deletions src/mds/MDCache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6973,8 +6973,12 @@ void MDCache::handle_cache_expire(MCacheExpire *m)
dn = dir->lookup(p->first.first, p->first.second);
}

if (!dn)
dout(0) << " missing dentry for " << p->first.first << " snap " << p->first.second << " in " << *dir << dendl;
if (!dn) {
if (dir)
dout(0) << " missing dentry for " << p->first.first << " snap " << p->first.second << " in " << *dir << dendl;
else
dout(0) << " missing dentry for " << p->first.first << " snap " << p->first.second << dendl;
}
assert(dn);

if (nonce == dn->get_replica_nonce(from)) {
Expand Down Expand Up @@ -10112,6 +10116,7 @@ void MDCache::handle_discover(MDiscover *dis)
<< dendl;

cur = get_inode(dis->get_base_ino());
assert(cur);

// add root
reply->starts_with = MDiscoverReply::INODE;
Expand Down
9 changes: 7 additions & 2 deletions src/mon/PGMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1978,12 +1978,17 @@ int PGMonitor::dump_stuck_pg_stats(stringstream &ds,
{
PGMap::StuckPG stuck_type;
string type = args[0];

if (type == "inactive")
stuck_type = PGMap::STUCK_INACTIVE;
if (type == "unclean")
else if (type == "unclean")
stuck_type = PGMap::STUCK_UNCLEAN;
if (type == "stale")
else if (type == "stale")
stuck_type = PGMap::STUCK_STALE;
else {
ds << "Unknown type: " << type << std::endl;
return 0;
}

utime_t now(ceph_clock_now(g_ceph_context));
utime_t cutoff = now - utime_t(threshold, 0);
Expand Down
3 changes: 3 additions & 0 deletions src/os/FileStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1736,6 +1736,9 @@ int FileStore::queue_transactions(Sequencer *posr, list<Transaction*> &tls,
tls, &onreadable, &ondisk, &onreadable_sync);
if (g_conf->filestore_blackhole) {
dout(0) << "queue_transactions filestore_blackhole = TRUE, dropping transaction" << dendl;
delete ondisk;
delete onreadable;
delete onreadable_sync;
return 0;
}

Expand Down
2 changes: 2 additions & 0 deletions src/osd/ReplicatedBackend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ class RPGTransaction : public PGBackend::PGTransaction {
PGTransaction *_to_append
) {
RPGTransaction *to_append = dynamic_cast<RPGTransaction*>(_to_append);
assert(to_append);
t->append(*(to_append->t));
for (set<hobject_t>::iterator i = to_append->temp_added.begin();
i != to_append->temp_added.end();
Expand Down Expand Up @@ -492,6 +493,7 @@ void ReplicatedBackend::submit_transaction(
OpRequestRef orig_op)
{
RPGTransaction *t = dynamic_cast<RPGTransaction*>(_t);
assert(t);
ObjectStore::Transaction *op_t = t->get_transaction();

assert(t->get_temp_added().size() <= 1);
Expand Down
9 changes: 8 additions & 1 deletion src/osd/ReplicatedPG.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5227,8 +5227,12 @@ int ReplicatedPG::fill_in_copy_get(
ctx->obc,
&out_attrs,
true);
if (result < 0)
if (result < 0) {
if (cb) {
delete cb;
}
return result;
}
cursor.attr_complete = true;
dout(20) << " got attrs" << dendl;
}
Expand All @@ -5250,6 +5254,9 @@ int ReplicatedPG::fill_in_copy_get(
result = pgbackend->objects_read_sync(
oi.soid, cursor.data_offset, left, &bl);
if (result < 0)
if (cb) {
delete cb;
}
return result;
}
assert(result <= left);
Expand Down
2 changes: 1 addition & 1 deletion src/osdc/Objecter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,7 @@ int Objecter::recalc_op_target(Op *op)
acting.size() > 1) {
// look for a local replica. prefer the primary if the
// distance is the same.
int best;
int best = -1;
int best_locality;
for (unsigned i = 0; i < acting.size(); ++i) {
int locality = osdmap->crush->get_common_ancestor_distance(
Expand Down
1 change: 1 addition & 0 deletions src/rgw/rgw_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ req_state::req_state(CephContext *_cct, class RGWEnv *e) : cct(_cct), cio(NULL),
perm_mask = 0;
content_length = 0;
object = NULL;
bucket_exists = false;
has_bad_meta = false;
length = NULL;
copy_source = NULL;
Expand Down
1 change: 1 addition & 0 deletions src/test/librados/c_read_operations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ TEST_F(CReadOpsTest, ExecUserBuf) {

// buffer too short
bytes_read = 1024;
rados_release_read_op(op);
op = rados_create_read_op();
rados_read_op_exec_user_buf(op, "rbd", "get_all_features", NULL, 0, out,
sizeof(features) - 1, &bytes_read, &rval);
Expand Down
3 changes: 3 additions & 0 deletions src/test/librados/c_write_operations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ TEST(LibRadosCWriteOps, Xattrs) {
ASSERT_EQ(-125, rados_write_op_operate(op, ioctx, "test", NULL, 0));

rados_release_write_op(op);
rados_ioctx_destroy(ioctx);
ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}

Expand Down Expand Up @@ -113,6 +114,7 @@ TEST(LibRadosCWriteOps, Write) {
ASSERT_EQ(-2, rados_read(ioctx, "test", hi, 4, 0));
rados_release_write_op(op);

rados_ioctx_destroy(ioctx);
ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}

Expand All @@ -135,5 +137,6 @@ TEST(LibRadosCWriteOps, Exec) {
hi[12] = '\0';
ASSERT_EQ(0, strcmp("Hello, test!", hi));

rados_ioctx_destroy(ioctx);
ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
3 changes: 2 additions & 1 deletion src/test/objectstore/store_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,8 @@ class SyntheticWorkloadState {
++in_flight;
}
struct stat buf;
store->stat(cid, hoid, &buf);
int r = store->stat(cid, hoid, &buf);
ASSERT_EQ(0, r);
ASSERT_TRUE(buf.st_size == contents[hoid].length());
{
Mutex::Locker locker(lock);
Expand Down

0 comments on commit 32a4e90

Please sign in to comment.