]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: fix shared_ptr usage
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Wed, 24 Aug 2011 21:50:26 +0000 (14:50 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Wed, 24 Aug 2011 21:50:26 +0000 (14:50 -0700)
shared_ptr calls the disposal function even when the pointer is null
that is being disposed of.

Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/rbd.cc

index b398b99d5b2f670fd2146bffb307826364b103d4..6a7f991fc653b93f8d5c2764a0636352a71c6958 100644 (file)
@@ -579,11 +579,17 @@ static int read_file(const char *filename, char *buf, size_t bufsize)
     return r;
 }
 
+void do_closedir(DIR *dp)
+{
+  if (dp)
+    closedir(dp);
+}
+
 static int do_kernel_showmapped()
 {
   int r;
   const char *devices_path = "/sys/bus/rbd/devices";
-  std::tr1::shared_ptr<DIR> device_dir(opendir(devices_path), closedir);
+  std::tr1::shared_ptr<DIR> device_dir(opendir(devices_path), do_closedir);
   if (!device_dir.get()) {
     r = -errno;
     cerr << "Could not open " << devices_path << ": " << cpp_strerror(-r) << std::endl;