]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
src/libcephfs.cc: Cleanup nullptr initializations against deleted objects, etc 19007/head
authorShinobu Kinjo <shinobu@redhat.com>
Sat, 18 Nov 2017 22:18:53 +0000 (07:18 +0900)
committerShinobu Kinjo <shinobu@redhat.com>
Sat, 18 Nov 2017 22:24:46 +0000 (07:24 +0900)
Signed-off-by: Shinobu Kinjo <shinobu@redhat.com>
src/libcephfs.cc

index 74652da147280c27ee48002268d178ca2b36dd11..be92023e88bfecb41261b1a84921896360bf8bad 100644 (file)
@@ -41,12 +41,12 @@ public:
     : 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();
     }
   }
@@ -57,7 +57,7 @@ public:
       shutdown();
       if (cct) {
        cct->put();
-       cct = NULL;
+       cct = nullptr;
       }
     }
     catch (const std::exception& e) {
@@ -154,15 +154,15 @@ public:
       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;
     }
   }
 
@@ -178,10 +178,10 @@ public:
 
   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;
   }
@@ -194,7 +194,7 @@ public:
     ret = cct->_conf->parse_argv(args);
     if (ret)
        return ret;
-    cct->_conf->apply_changes(NULL);
+    cct->_conf->apply_changes(nullptr);
     return 0;
   }
 
@@ -206,7 +206,7 @@ public:
     int ret = conf->parse_argv(args);
     if (ret)
       return ret;
-    conf->apply_changes(NULL);
+    conf->apply_changes(nullptr);
     return 0;
   }
 
@@ -215,7 +215,7 @@ public:
     int ret = cct->_conf->set_val(option, value);
     if (ret)
       return ret;
-    cct->_conf->apply_changes(NULL);
+    cct->_conf->apply_changes(nullptr);
     return 0;
   }
 
@@ -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)
@@ -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)
@@ -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;
 }
 
@@ -349,6 +350,7 @@ extern "C" int ceph_release(struct ceph_mount_info *cmount)
   if (cmount->is_mounted())
     return -EISCONN;
   delete cmount;
+  cmount = nullptr;
   return 0;
 }
 
@@ -356,6 +358,7 @@ 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)
@@ -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);
@@ -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));
 }
@@ -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;
@@ -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);