You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2011/06/05 05:28:45 UTC

svn commit: r1131605 - in /incubator/mesos/trunk/src: ft_messaging.cpp ft_messaging.hpp

Author: benh
Date: Sun Jun  5 03:28:44 2011
New Revision: 1131605

URL: http://svn.apache.org/viewvc?rev=1131605&view=rev
Log:
fixed memory leak

Modified:
    incubator/mesos/trunk/src/ft_messaging.cpp
    incubator/mesos/trunk/src/ft_messaging.hpp

Modified: incubator/mesos/trunk/src/ft_messaging.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/ft_messaging.cpp?rev=1131605&r1=1131604&r2=1131605&view=diff
==============================================================================
--- incubator/mesos/trunk/src/ft_messaging.cpp (original)
+++ incubator/mesos/trunk/src/ft_messaging.cpp Sun Jun  5 03:28:44 2011
@@ -64,8 +64,15 @@ string FTMessaging::getNextId() {
   return uniqPrefix + ":" + lexical_cast<string>(msgId++);
 }                                                      
   
-void FTMessaging::gotAck(string ftId) {
+void FTMessaging::gotAck(const string &ftId) {
   DLOG(INFO) << "FT: Got ack, deleting outstanding msg " << ftId;
+  deleteMessage(ftId);
+}
+
+void FTMessaging::deleteMessage(const string &ftId) {
+  struct FTStoredMsg & msg = outMsgs[ftId];
+  if (msg.callback != NULL)
+    delete msg.callback;     // ugly and sad. shared_ptr would have been better
   outMsgs.erase(ftId);
 }
 
@@ -79,15 +86,14 @@ void FTMessaging::sendOutstanding() {
     if (msg.callback != NULL) {
       DLOG(INFO) << "FT: calling timeout listener";
       msg.callback->timeout();
-      delete msg.callback; // ugly and sad. shared_ptr would have been better
-      outMsgs.erase(ftId);
+      deleteMessage(ftId);
     } else if (msg.count < FT_MAX_RESENDS) {
       DLOG(INFO) << "FT: RE-sending " << msg.ftId << " attempt:" << msg.count;
       Process::post(master, msg.id, msg.data.data(), msg.data.size());
       msg.count++;
     } else {
       DLOG(INFO) << "FT: Not RE-sending " << msg.ftId << " reached limit " << FT_MAX_RESENDS;
-      outMsgs.erase(ftId);
+      deleteMessage(ftId);
     }
   }
 

Modified: incubator/mesos/trunk/src/ft_messaging.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/ft_messaging.hpp?rev=1131605&r1=1131604&r2=1131605&view=diff
==============================================================================
--- incubator/mesos/trunk/src/ft_messaging.hpp (original)
+++ incubator/mesos/trunk/src/ft_messaging.hpp Sun Jun  5 03:28:44 2011
@@ -143,7 +143,7 @@ public:
    * Removes any pending message with a given id. This is to be called upon the receipt of a message.
    * @param ftId string representing the unique FT id of the message.
    */
-  void gotAck(string ftId);
+  void gotAck(const string &ftId);
 
   /**
    * Attempts to send all pending messages to the current master. Pending messages are messages that have not been acked yet.
@@ -198,6 +198,8 @@ private:
 
   static FTMessaging *instance;
 
+  void deleteMessage(const string &ftId);
+
   FTMessaging();
   FTMessaging(PID _master);