KanikaVarma / sudzc

Automatically exported from code.google.com/p/sudzc
0 stars 0 forks source link

memory leak in Soap.m #47

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Make a soap request

What is the expected output? What do you see instead?
I should see no memory leaks. I see a memory leak in this method: // Creates 
the XML request for the SOAP envelope with optional SOAP headers.
+ (NSString*) createEnvelope: (NSString*) method forNamespace: (NSString*) ns 
forParameters: (NSString*) params withHeaders: (NSDictionary*) headers

What version of the product are you using? On what operating system?
Latest code generated by sudzc.com on Lion.

Please provide any additional information below.

I think the fix would be to autorelease the mutable string s on the last line 
like return [s autorelease]; instead of return s; in this method:

// Creates the XML request for the SOAP envelope with optional SOAP headers.
+ (NSString*) createEnvelope: (NSString*) method forNamespace: (NSString*) ns 
forParameters: (NSString*) params withHeaders: (NSDictionary*) headers

Original issue reported on code.google.com by pritesh....@gmail.com on 7 May 2012 at 11:53

GoogleCodeExporter commented 9 years ago
The fix proposed solved the problem for me.
Thanks.

Original comment by joseluis...@gmail.com on 25 Jul 2012 at 11:32

GoogleCodeExporter commented 9 years ago
The fix doesn't make sense. The createEnvelope method uses

[NSMutableString string]

which is (according to apple convention), not a retaining function. In other 
words, calling the function will not retain the string so there should be no 
reason to release it.

Still, I applied the fix to my own code and it did do the trick for 
instruments... I'm really confused about this one.

Original comment by danielba...@gmail.com on 1 Aug 2012 at 9:07

GoogleCodeExporter commented 9 years ago
Hi people, 
I have dug the code and found the real fix for this.

The memory leak comes from line 69 of the SoapRequest.m: 
request.postData = [postData retain];

where [postData retain] is our created string, from createEnvelope method.

Next, I was looking at the request.postData variable declaration and I don't 
know why, it is declared as "id" type with a property with retain in 
SoapRequest class.

So what we have: a autoreleased object, which is assigned with retain to a 
property through a setter with retain and all-in-all => MemoryLeak.

I think all of you understand now how to fix it. 

For those who don't, please follow my changes to fix your leaks, as it 
perfectly works:
1. In SoapRequest.h replace variable declaration id postData to NSString* 
postData;
2. In SoapRequest.h replace its property declaration to @property (copy, 
nonatomic) NSString* postData; (Here, I additionally changed all of the 
NSString property delcarations to "copy")
3. In SoapRequest.m, method  (SoapRequest*) create: (SoapHandler*) handler 
action: (SEL) action urlString: (NSString*) urlString soapAction: (NSString*) 
soapAction postData: (NSString*) postData deserializeTo: (id) deserializeTo
change the row request.postData = [postData retain]; to request.postData = 
postData;.

These 3 steps will solve your problems. Hope it will be also implemented in the 
SudzcC framework as well.

Original comment by odan...@gmail.com on 30 Aug 2012 at 3:10