]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
fix: memory leak in IfaceMgr::receive4(), reference in IfaceMgr test (cppcheck)
authorTomek Mrugalski <tomasz@isc.org>
Thu, 29 Dec 2011 13:18:02 +0000 (14:18 +0100)
committerTomek Mrugalski <tomasz@isc.org>
Thu, 29 Dec 2011 13:18:02 +0000 (14:18 +0100)
src/lib/dhcp/iface_mgr.cc
src/lib/dhcp/tests/iface_mgr_unittest.cc

index dfdeecbd2e0c2d6510aacfa374d3992556f9633d..153ffdae7d785ba453f5a8b45b7f4a4baff0301e 100644 (file)
@@ -716,7 +716,7 @@ IfaceMgr::receive4() {
     struct in_addr to_addr;
     boost::shared_ptr<Pkt4> pkt;
     const uint32_t RCVBUFSIZE = 1500;
-    uint8_t* buf = (uint8_t*) malloc(RCVBUFSIZE);
+    static uint8_t buf[RCVBUFSIZE];
 
     memset(&control_buf_[0], 0, control_buf_len_);
     memset(&from_addr, 0, sizeof(from_addr));
@@ -747,7 +747,6 @@ IfaceMgr::receive4() {
 
     if (result < 0) {
         cout << "Failed to receive UDP4 data." << endl;
-        delete buf;
         return (boost::shared_ptr<Pkt4>()); // NULL
     }
 
@@ -784,7 +783,6 @@ IfaceMgr::receive4() {
     }
     if (!found_pktinfo) {
         cout << "Unable to find pktinfo" << endl;
-        delete buf;
         return (boost::shared_ptr<Pkt4>()); // NULL
     }
 #endif
index ce639450454ab2a9c9e9a24576955eafb18aa956..ee0769ddd184b90f96fa892fd8f5ca0c6c18169b 100644 (file)
@@ -675,7 +675,7 @@ size_t parse_mac(const std::string& textMac, uint8_t* mac, size_t macLen) {
 ///
 /// @param textFile name of a text file that holds output of ifconfig -a
 /// @param ifaces empty list of interfaces to be filled
-void parse_ifconfig(const std::string textFile, IfaceMgr::IfaceCollection& ifaces) {
+void parse_ifconfig(const std::string& textFile, IfaceMgr::IfaceCollection& ifaces) {
     fstream f(textFile.c_str());
 
     bool first_line = true;