[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: [PyKDE] Leaking in virtual handler
From: James Emerton <ephelon () gmail ! com>
Date: 2005-04-20 21:09:16
Message-ID: c9424d940504201409bbbad34 () mail ! gmail ! com
[Download RAW message or body]
I have found a memory leak owing to how SIP handles virtual methods.=20
If a type conversion is done by sipParseResult(), a new object is
allocated but never deleted.
I have an interface that returns a QString. If I implement this in
python and return a python string, a conversion to QString is
performed by creating a new QString instance. This instance is never
deallocated.
I have attached a patch which appears to correct this. I am not
entirely comfortable with the way I am detecting whether sipResOrig is
the same as the pointer contained in sipResObj.
James
["gencode.patch" (application/octet-stream)]
--- gencode.orig Wed Apr 20 11:50:54 2005
+++ gencode.c Wed Apr 20 13:42:29 2005
@@ -4194,7 +4194,8 @@ static void generateVirtualHandler(sipSp
generateResultType(&res_noconstref,fp);
- prcode(fp," *sipResOrig;\n");
+ /* James - initialise to NULL */
+ prcode(fp," *sipResOrig = NULL;\n");
}
/* Call the method. */
@@ -4264,11 +4265,26 @@ static void generateVirtualHandler(sipSp
);
/* Make a copy if needed. */
+ /* James - clean up the original to plug memory leak
+ What if this was not allocated with new? */
if (copy)
+ {
prcode(fp,
" else\n"
" sipRes = *sipResOrig;\n"
- );
+ );
+ if( res->atype == class_type )
+ prcode(fp,
+"\n"
+" if( sipResOrig && sipGetCppPtr((sipWrapper*)sipResObj, sipClass_%T) != sipResOrig )\n"
+" delete sipResOrig;\n"
+ ,res);
+ else
+ prcode(fp,
+"\n"
+" delete sipResOrig;\n"
+ );
+ }
if (isTransferVH(vhd))
prcode(fp,
_______________________________________________
PyKDE mailing list PyKDE@mats.imk.fraunhofer.de
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic