Browse code

b/f: small mem leak (AmSdp telev pl)

...which keeps popping up all the time again...

Stefan Sayer authored on 23/02/2011 23:27:27
Showing 2 changed files
... ...
@@ -162,11 +162,17 @@ int AmSdp::parse()
162 162
     }
163 163
   }
164 164
   
165
-  telephone_event_pt = findPayload("telephone-event");
165
+  telephone_event_pt.reset(findPayload("telephone-event"));
166 166
     
167 167
   return ret;
168 168
 }
169 169
 
170
+SdpPayload* AmSdp::telephoneEventPayload() const {
171
+  if (telephone_event_pt.get() == NULL)
172
+    return NULL;
173
+  return new SdpPayload(*telephone_event_pt.get());
174
+}
175
+
170 176
 void AmSdp::print(string& body) const
171 177
 {
172 178
   string out_buf =
... ...
@@ -444,10 +450,10 @@ const vector<SdpPayload*>& AmSdp::getCompatiblePayloads(AmPayloadProviderInterfa
444 450
 	
445 451
 bool AmSdp::hasTelephoneEvent()
446 452
 {
447
-  return telephone_event_pt != NULL;
453
+  return telephone_event_pt.get() != NULL;
448 454
 }
449 455
 
450
-const SdpPayload *AmSdp::findPayload(const string& name)
456
+SdpPayload *AmSdp::findPayload(const string& name)
451 457
 {
452 458
   vector<SdpMedia>::iterator m_it;
453 459
 
... ...
@@ -33,6 +33,7 @@
33 33
 #include <vector>
34 34
 #include <netinet/in.h>
35 35
 #include "AmPlugIn.h"
36
+#include <memory>
36 37
 using std::string;
37 38
 
38 39
 
... ...
@@ -157,12 +158,12 @@ class AmSdp
157 158
 
158 159
   // Remote payload type for 
159 160
   // 'telephone-event'
160
-  const SdpPayload *telephone_event_pt;
161
+  std::auto_ptr<SdpPayload> telephone_event_pt;
161 162
 
162 163
   /**
163
-   * Find payload by name
164
+   * Find payload by name, return cloned object
164 165
    */
165
-  const SdpPayload *findPayload(const string& name);
166
+  SdpPayload *findPayload(const string& name);
166 167
 
167 168
 public:
168 169
   // parsed SDP definition
... ...
@@ -226,7 +227,7 @@ public:
226 227
    */
227 228
   bool hasTelephoneEvent();
228 229
 
229
-  const SdpPayload *telephoneEventPayload() const { return telephone_event_pt; }
230
+  SdpPayload *telephoneEventPayload() const;
230 231
 };
231 232
 
232 233
 #endif