]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
always throw by value; always catch by const ref
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Mon, 4 Oct 2010 17:47:30 +0000 (10:47 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Mon, 4 Oct 2010 17:50:19 +0000 (10:50 -0700)
Always throw exceptions by value rather than as pointers. Always catch
exceptions as const references to avoid unecessary copying. This fixes a
few minor memory leaks and should simplify handling exceptions in the
future.

Signed-off-by: Colin McCabe <colinm@hq.newdream.net>
16 files changed:
src/auth/cephx/CephxProtocol.cc
src/auth/none/AuthNoneAuthorizeHandler.cc
src/cauthtool.cc
src/cls_rbd.cc
src/common/assert.cc
src/cosd.cc
src/include/buffer.h
src/mon/AuthMonitor.cc
src/mon/MonCaps.cc
src/mon/MonClient.cc
src/msg/Message.cc
src/osd/OSD.cc
src/osd/OSDCaps.cc
src/osd/PG.cc
src/osd/osd_types.h
src/osdmaptool.cc

index c7579231dd049fe3608dc80b6811877569f217e8..a733d79d9bfa893d59661a5f34b6ef546aa96262 100644 (file)
@@ -429,9 +429,8 @@ bool CephXAuthorizer::verify_reply(bufferlist::iterator& indata)
       dout(0) << "verify_authorizer_reply coudln't decrypt with " << session_key << dendl;
       return false;
     }
-  } catch (buffer::error *e) {
+  } catch (const buffer::error &e) {
     dout(0) << "verify_authorizer_reply exception in decode_decrypt with " << session_key << dendl;
-    delete e;
     return false;
   }
 
index fbc655b5cd0ad64efad47c39f65bab09caa71cd6..0848e9fed5843904eb187451403d38257fc64fb8 100644 (file)
@@ -15,7 +15,7 @@ uint64_t *auid)
     ::decode(struct_v, iter);
     ::decode(entity_name, iter);
     ::decode(global_id, iter);
-  } catch (buffer::error *err) {
+  } catch (const buffer::error &err) {
     dout(0) << "AuthNoneAuthorizeHandle::verify_authorizer() failed to decode" << dendl;
     return false;
   }
index 1b2b34c8120f2678c162148c3199715ee553c378..d51dbae97bc6d878ac3bef50755f242e8acfc641 100644 (file)
@@ -140,7 +140,7 @@ int main(int argc, const char **argv)
       try {
        bufferlist::iterator iter = bl.begin();
        ::decode(keyring, iter);
-      } catch (buffer::error *err) {
+      } catch (const buffer::error &err) {
        cerr << "error reading file " << fn << std::endl;
        exit(1);
       }
@@ -159,7 +159,7 @@ int main(int argc, const char **argv)
       try {
        bufferlist::iterator iter = obl.begin();
        ::decode(other, iter);
-      } catch (buffer::error *err) {
+      } catch (const buffer::error &err) {
        cerr << "error reading file " << import_keyring << std::endl;
        exit(1);
       }
@@ -188,7 +188,7 @@ int main(int argc, const char **argv)
     string ekey(add_key);
     try {
       eauth.key.decode_base64(ekey);
-    } catch (buffer::error *err) {
+    } catch (const buffer::error &err) {
       cerr << "can't decode key '" << add_key << "'" << std::endl;
       exit(1);
     }
index 406a5c87a5035bb6b6cd949a691f92fe10028d54..74bfeffdc3fea8fbcd28c13f15e764e23800e480 100644 (file)
@@ -115,7 +115,7 @@ int snapshot_add(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
   try {
     ::decode(s, iter);
     ::decode(snap_id, iter);
-  } catch (buffer::error *err) {
+  } catch (const buffer::error &err) {
     return -EINVAL;
   }
   snap_name = s.c_str();
@@ -192,7 +192,7 @@ int snapshot_revert(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
 
   try {
     ::decode(s, iter);
-  } catch (buffer::error *err) {
+  } catch (const buffer::error &err) {
     return -EINVAL;
   }
   snap_name = s.c_str();
@@ -267,7 +267,7 @@ int snapshot_remove(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
 
   try {
     ::decode(s, iter);
-  } catch (buffer::error *err) {
+  } catch (const buffer::error &err) {
     return -EINVAL;
   }
   snap_name = s.c_str();
index 5051aa733aab5b11f582befe961712fe8040e166..a045c47972c172e1ad981743f40857f3098501b3 100644 (file)
@@ -27,7 +27,7 @@ void __ceph_assert_fail(const char *assertion, const char *file, int line, const
   cerr.flush();
 
   if (1) {
-    throw new FailedAssertion(bt);
+    throw FailedAssertion(bt);
   } else {
     // make myself core dump.
     char *p = 0;
index f887b1ed610fbd4ab814368686b6d8b881e6797b..ec01c2386ee7bd5b17edd21b438b727559116a4d 100644 (file)
@@ -102,7 +102,7 @@ int main(int argc, const char **argv)
        try {
          ::decode(e, p);
        }
-       catch (buffer::error *e) {
+       catch (const buffer::error &e) {
          cerr << "failed to decode LogEntry at offset " << pos << std::endl;
          return 1;
        }
index 8bdbc8eccb03980775c942aa0f44771ad8268731..a84dc62ab1239f9e22cdb8a31e6e1f71e89ded16 100644 (file)
@@ -227,7 +227,7 @@ private:
     raw_mmap_pages(unsigned l) : raw(l) {
       data = (char*)::mmap(NULL, len, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0);
       if (!data)
-       throw new bad_alloc;
+       throw bad_alloc();
       inc_total_alloc(len);
       bdout << "raw_mmap " << this << " alloc " << (void *)data << " " << l << " " << buffer_total_alloc.read() << bendl;
     }
@@ -250,10 +250,10 @@ private:
       data = 0;
       int r = ::posix_memalign((void**)(void*)&data, PAGE_SIZE, len);
       if (r)
-       throw new bad_alloc;
+       throw bad_alloc();
 #endif /* DARWIN */
       if (!data)
-       throw new bad_alloc;
+       throw bad_alloc();
       inc_total_alloc(len);
       bdout << "raw_posix_aligned " << this << " alloc " << (void *)data << " " << l << " " << buffer_total_alloc.read() << bendl;
     }
@@ -471,7 +471,7 @@ public:
       assert(_raw);
       if (!((o >= 0 && o <= _len) &&
            (l >= 0 && o+l <= _len)))
-       throw new end_of_buffer;
+       throw end_of_buffer();
       memcpy(dest, c_str()+o, l);
     }
 
@@ -590,7 +590,7 @@ public:
        p_off += o;
        while (p_off > 0) {
          if (p == ls->end())
-           throw new end_of_buffer;
+           throw end_of_buffer();
          if (p_off >= p->length()) {
            // skip this buffer
            p_off -= p->length();
@@ -612,12 +612,12 @@ public:
 
       char operator*() {
        if (p == ls->end())
-         throw new end_of_buffer;
+         throw end_of_buffer();
        return (*p)[p_off];
       }
       iterator& operator++() {
        if (p == ls->end())
-         throw new end_of_buffer;
+         throw end_of_buffer();
        advance(1);
        return *this;
       }
@@ -629,7 +629,7 @@ public:
        if (p == ls->end()) seek(off);
        while (len > 0) {
          if (p == ls->end())
-           throw new end_of_buffer;
+           throw end_of_buffer();
 
          unsigned howmuch = p->length() - p_off;
          if (len < howmuch) howmuch = len;
@@ -650,7 +650,7 @@ public:
        if (p == ls->end()) seek(off);
        while (len > 0) {
          if (p == ls->end())
-           throw new end_of_buffer;
+           throw end_of_buffer();
          
          unsigned howmuch = p->length() - p_off;
          if (len < howmuch) howmuch = len;
@@ -665,13 +665,13 @@ public:
        if (p == ls->end()) seek(off);
        while (len > 0) {
          if (p == ls->end())
-           throw new end_of_buffer;
+           throw end_of_buffer();
 
          unsigned howmuch = p->length() - p_off;
          const char *c_str = p->c_str();
          if (len < howmuch) howmuch = len;
          if (memchr(c_str + p_off, '\0', howmuch))
-           throw new malformed_input("embedded NULL in string!");
+           throw malformed_input("embedded NULL in string!");
          dest.append(c_str + p_off, howmuch);
 
          len -= howmuch;
@@ -686,7 +686,7 @@ public:
        if (p == ls->end()) seek(off);
        while (len > 0) {
          if (p == ls->end())
-           throw new end_of_buffer;
+           throw end_of_buffer();
 
          unsigned howmuch = p->length() - p_off;
          if (len < howmuch) howmuch = len;
@@ -891,7 +891,7 @@ public:
     void copy(unsigned off, unsigned len, char *dest) const {
       assert(off >= 0);
       if (off + len > length())
-       throw new end_of_buffer;
+       throw end_of_buffer();
       if (last_p.get_off() != off) 
        last_p.seek(off);
       last_p.copy(len, dest);
@@ -900,7 +900,7 @@ public:
     void copy(unsigned off, unsigned len, list &dest) const {
       assert(off >= 0);
       if (off + len > length())
-       throw new end_of_buffer;
+       throw end_of_buffer();
       if (last_p.get_off() != off) 
        last_p.seek(off);
       last_p.copy(len, dest);
@@ -915,7 +915,7 @@ public:
     void copy_in(unsigned off, unsigned len, const char *src) {
       assert(off >= 0);
       if (off + len > length())
-       throw new end_of_buffer;
+       throw end_of_buffer();
       
       if (last_p.get_off() != off) 
        last_p.seek(off);
@@ -1012,7 +1012,7 @@ public:
      */
     const char& operator[](unsigned n) const {
       if (n >= _len)
-       throw new end_of_buffer;
+       throw end_of_buffer();
 
       for (std::list<ptr>::const_iterator p = _buffers.begin();
           p != _buffers.end();
@@ -1040,7 +1040,7 @@ public:
 
     void substr_of(const list& other, unsigned off, unsigned len) {
       if (off + len > other.length())
-       throw new end_of_buffer;
+       throw end_of_buffer();
 
       clear();
       
@@ -1080,7 +1080,7 @@ public:
     // funky modifer
     void splice(unsigned off, unsigned len, list *claim_by=0 /*, bufferlist& replace_with */) {    // fixme?
       if (off >= length())
-       throw new end_of_buffer;
+       throw end_of_buffer();
 
       assert(len > 0);
       //cout << "splice off " << off << " len " << len << " ... mylen = " << length() << std::endl;
index 8caa5c300277e357e8a78feecbb93e34e71035c7..5250cbe24e63f221dc05f1c333d9bf0a30e67331 100644 (file)
@@ -111,7 +111,7 @@ void AuthMonitor::create_initial(bufferlist& bl)
         bufferlist::iterator iter = bl.begin();
         ::decode(keyring, iter);
         read_ok = true;
-      } catch (buffer::error *err) {
+      } catch (const buffer::error &err) {
         cerr << "error reading file " << g_conf.keyring << std::endl;
       }
       if (read_ok)
@@ -380,7 +380,7 @@ bool AuthMonitor::prep_auth(MAuth *m, bool paxos_writable)
       ::decode(supported, indata);
       ::decode(entity_name, indata);
       ::decode(s->global_id, indata);
-    } catch (buffer::error *e) {
+    } catch (const buffer::error &e) {
       dout(10) << "failed to decode initial auth message" << dendl;
       ret = -EINVAL;
       goto reply;
@@ -436,7 +436,7 @@ bool AuthMonitor::prep_auth(MAuth *m, bool paxos_writable)
       s->caps.parse(iter);
       s->caps.set_auid(auid);
     }
-  } catch (buffer::error *err) {
+  } catch (const buffer::error &err) {
     ret = -EINVAL;
     dout(0) << "caught error when trying to handle auth request, probably malformed request" << dendl;
   }
@@ -562,7 +562,7 @@ bool AuthMonitor::prepare_command(MMonCommand *m)
       KeyRing keyring;
       try {
         ::decode(keyring, iter);
-      } catch (buffer::error *err) {
+      } catch (const buffer::error &err) {
         ss << "error decoding keyring";
         rs = -EINVAL;
         goto done;
@@ -589,7 +589,7 @@ bool AuthMonitor::prepare_command(MMonCommand *m)
       KeyRing keyring;
       try {
         ::decode(keyring, iter);
-      } catch (buffer::error *err) {
+      } catch (const buffer::error &err) {
         ss << "error decoding keyring";
         rs = -EINVAL;
         goto done;
index 13728f3578dd475ba2e8a3cab4ab5e51eac57d1d..ac3cc28deb93af6ac0fdcb5a87e92225da0e8e8f 100644 (file)
@@ -204,7 +204,7 @@ do { \
         
       }
     }
-  } catch (buffer::error *err) {
+  } catch (const buffer::error &err) {
     return false;
   }
 
index 52c950bb2fb670b43fda6710b215312c9e736dfd..232ba652b3c75f9b3ace160c3c561250fccfbf6f 100644 (file)
@@ -54,7 +54,7 @@ int MonClient::build_initial_monmap()
     try {
       r = monmap.read(monmap_fn);
     }
-    catch (buffer::error *e) {
+    catch (const buffer::error &e) {
       r = -EINVAL;
     }
     if (r >= 0)
index 9687332e24a7472ca95b2f91c9b8c5277ae563b6..777772c350a831bfd3b9bc8a393b804760f7721b 100644 (file)
@@ -513,11 +513,10 @@ Message *decode_message(ceph_msg_header& header, ceph_msg_footer& footer,
   try {
     m->decode_payload();
   }
-  catch (buffer::error *e) {
+  catch (const buffer::error &e) {
     dout(0) << "failed to decode message of type " << type
            << " v" << header.version
-           << ": " << *e << dendl;
-    delete e;
+           << ": " << e.what() << dendl;
     if (g_conf.ms_die_on_bad_msg)
       assert(0);
     return 0;
index e1489c4e9ad1e4247d771e43f3165478ee3effc8..5d1fc916e18629394525663eaa920e278f2380f2 100644 (file)
@@ -1435,7 +1435,7 @@ void OSD::heartbeat()
       in.close();
     }
   }
-  catch (ios::failure f) {
+  catch (const ios::failure &f) {
     dout(0) << "heartbeat: failed to read /proc/loadavg" << dendl;
   }
 
index 6a6a61901925b07e4c87eb5fe0990f54e03b6b43..4a8d27ec5465e4ed86e1b094fc4543e8710bda66 100644 (file)
@@ -192,7 +192,7 @@ do { \
         
       }
     }
-  } catch (buffer::error *err) {
+  } catch (const buffer::error &err) {
     return false;
   }
 
index 218ec26db980132dc3fe9f7b70bfe72d117bee8e..c05eed65cc6989b84de0305a7149b0dd89282c58 100644 (file)
@@ -2321,13 +2321,13 @@ bool PG::check_log_for_corruption(ObjectStore *store)
        try {
          ::decode(e, p);
        }
-       catch (buffer::error *e) {
+       catch (const buffer::error &e) {
          dout(0) << "corrupt entry at " << pos << dendl;
          ss << "corrupt entry at offset " << pos;
          ok = false;
          break;
        }
-       catch(std::bad_alloc a) {
+       catch(const std::bad_alloc &a) {
          dout(0) << "corrupt entry at " << pos << dendl;
          ss << "corrupt entry at offset " << pos;
          ok = false;
index 0796d61ff6cea94f658fb4bee1057a1bdd0669fc..88fc9833fc626bd25b2afcdd078fd8063224b237 100644 (file)
@@ -785,7 +785,7 @@ struct pg_pool_t {
     __u8 struct_v;
     ::decode(struct_v, bl);
     if (struct_v > CEPH_PG_POOL_VERSION)
-      throw new buffer::error;
+      throw buffer::error();
     ::decode(v, bl);
     ::decode_nohead(v.num_snaps, snaps, bl);
     removed_snaps.decode_nohead(v.num_removed_snap_intervals, bl);
index f6e65d050fbdf3c3fdecaa4b2ab61cdf54d37de5..6dcb3fe8356badb7b1de28cc1605b1db1296e640 100644 (file)
@@ -115,7 +115,7 @@ int main(int argc, const char **argv)
       try {
        osdmap.decode(bl);
       }
-      catch (buffer::error *e) {
+      catch (const buffer::error &e) {
        cerr << me << ": error decoding osdmap '" << fn << "'" << std::endl;
        return -1;
       }