Skip to content

Commit

Permalink
src/libcephfs.cc: Cleanup nullptr initializations against deleted obj…
Browse files Browse the repository at this point in the history
…ects, etc

Signed-off-by: Shinobu Kinjo <[email protected]>
  • Loading branch information
shinobu-x committed Nov 18, 2017
1 parent b9ea759 commit 0279c6f
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions src/libcephfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ struct ceph_mount_info
: default_perms(),
mounted(false),
inited(false),
client(NULL),
monclient(NULL),
messenger(NULL),
client(nullptr),
monclient(nullptr),
messenger(nullptr),
cct(cct_)
{
if (cct_ != nullptr) {
if (cct_) {
cct->get();
}
}
Expand All @@ -57,7 +57,7 @@ struct ceph_mount_info
shutdown();
if (cct) {
cct->put();
cct = NULL;
cct = nullptr;
}
}
catch (const std::exception& e) {
Expand Down Expand Up @@ -154,15 +154,15 @@ struct ceph_mount_info
messenger->shutdown();
messenger->wait();
delete messenger;
messenger = NULL;
messenger = nullptr;
}
if (monclient) {
delete monclient;
monclient = NULL;
monclient = nullptr;
}
if (client) {
delete client;
client = NULL;
client = nullptr;
}
}

Expand All @@ -178,10 +178,10 @@ struct ceph_mount_info

int conf_read_file(const char *path_list)
{
int ret = cct->_conf->parse_config_files(path_list, NULL, 0);
int ret = cct->_conf->parse_config_files(path_list, nullptr, 0);
if (ret)
return ret;
cct->_conf->apply_changes(NULL);
cct->_conf->apply_changes(nullptr);
cct->_conf->complain_about_parse_errors(cct);
return 0;
}
Expand All @@ -194,7 +194,7 @@ struct ceph_mount_info
ret = cct->_conf->parse_argv(args);
if (ret)
return ret;
cct->_conf->apply_changes(NULL);
cct->_conf->apply_changes(nullptr);
return 0;
}

Expand All @@ -206,7 +206,7 @@ struct ceph_mount_info
int ret = conf->parse_argv(args);
if (ret)
return ret;
conf->apply_changes(NULL);
conf->apply_changes(nullptr);
return 0;
}

Expand All @@ -215,7 +215,7 @@ struct ceph_mount_info
int ret = cct->_conf->set_val(option, value);
if (ret)
return ret;
cct->_conf->apply_changes(NULL);
cct->_conf->apply_changes(nullptr);
return 0;
}

Expand Down Expand Up @@ -263,7 +263,7 @@ static void do_out_buffer(bufferlist& outbl, char **outbuf, size_t *outbuflen)
*outbuf = (char *)malloc(outbl.length());
memcpy(*outbuf, outbl.c_str(), outbl.length());
} else {
*outbuf = NULL;
*outbuf = nullptr;
}
}
if (outbuflen)
Expand All @@ -277,7 +277,7 @@ static void do_out_buffer(string& outbl, char **outbuf, size_t *outbuflen)
*outbuf = (char *)malloc(outbl.length());
memcpy(*outbuf, outbl.c_str(), outbl.length());
} else {
*outbuf = NULL;
*outbuf = nullptr;
}
}
if (outbuflen)
Expand Down Expand Up @@ -333,9 +333,10 @@ extern "C" int ceph_create(struct ceph_mount_info **cmount, const char * const i

CephContext *cct = common_preinit(iparams, CODE_ENVIRONMENT_LIBRARY, 0);
cct->_conf->parse_env(); // environment variables coverride
cct->_conf->apply_changes(NULL);
cct->_conf->apply_changes(nullptr);
int ret = ceph_create_with_context(cmount, cct);
cct->put();
cct = nullptr;
return ret;
}

Expand All @@ -349,13 +350,15 @@ extern "C" int ceph_release(struct ceph_mount_info *cmount)
if (cmount->is_mounted())
return -EISCONN;
delete cmount;
cmount = nullptr;
return 0;
}

extern "C" void ceph_shutdown(struct ceph_mount_info *cmount)
{
cmount->shutdown();
delete cmount;
cmount = nullptr;
}

extern "C" int ceph_conf_read_file(struct ceph_mount_info *cmount, const char *path)
Expand Down Expand Up @@ -383,7 +386,7 @@ extern "C" int ceph_conf_set(struct ceph_mount_info *cmount, const char *option,
extern "C" int ceph_conf_get(struct ceph_mount_info *cmount, const char *option,
char *buf, size_t len)
{
if (buf == NULL) {
if (!buf) {
return -EINVAL;
}
return cmount->conf_get(option, buf, len);
Expand Down Expand Up @@ -505,7 +508,7 @@ extern "C" struct dirent * ceph_readdir(struct ceph_mount_info *cmount, struct c
if (!cmount->is_mounted()) {
/* Client::readdir also sets errno to signal errors. */
errno = ENOTCONN;
return NULL;
return nullptr;
}
return cmount->get_client()->readdir(reinterpret_cast<dir_result_t*>(dirp));
}
Expand Down Expand Up @@ -1397,8 +1400,8 @@ extern "C" int ceph_ll_lookup_inode(
return r;
}

assert(inode != NULL);
assert(*inode != NULL);
assert(inode);
assert(*inode);

// Request the parent inode, so that we can look up the name
Inode *parent;
Expand All @@ -1414,7 +1417,7 @@ extern "C" int ceph_ll_lookup_inode(
}
// FIXME: I don't think this works; lookup_parent() returns 0 if the parent
// is already in cache
assert(parent != NULL);
assert(parent);

// Finally, get the name (dentry) of the requested inode
r = (cmount->get_client())->lookup_name(*inode, parent, cmount->default_perms);
Expand Down

0 comments on commit 0279c6f

Please sign in to comment.