[PyQt] [BUG] Issues with overriding QSGMaterialShader::attributeNames()

Vladimir Rutsky rutsky.vladimir at gmail.com
Tue Jun 2 11:47:27 BST 2015


Hello,

1. Overrided in Python QSGMaterialShader::attributeNames() always
returns NULL to Qt C++ code.

In PyQt-gpl-5.4.1/sip/QtQuick/qsgmaterial.sip code for
attributeNames() method stores result in variable "result" and never
touches "sipRes" variable, which is returned at the end of function.

Attached patch fixes this issue by assigning "sipRes" to "result" (I'm
not sure is this intented behavior in case of errors).

2. Calling overriden in Python QSGMaterialShader::attributeNames()
from Qt C++ code leads to memory leaks.

Each call to attributeNames() creates copy of strings
(PyQt-gpl-5.4.1/sip/QtQuick/qsgmaterial.sip):

                // Note that the converted value will leak.  This
shouldn't matter
                // because the data should be static anyway.
                result = new char *[PyList_GET_SIZE(names) + 1];
                result[PyList_GET_SIZE(names)] = 0;

And attributeNames() is called e.g. in each
Renderer::renderUnmergedBatch(), which can lead to unlimited memory
leaks.


Regards,

Vladimir Rutsky
-------------- next part --------------
--- PyQt-gpl-5.4.1/sip/QtQuick/qsgmaterial.sip_orig	2015-06-01 16:58:24.558803167 +0300
+++ PyQt-gpl-5.4.1/sip/QtQuick/qsgmaterial.sip	2015-06-02 03:52:14.778574666 +0300
@@ -117,6 +117,8 @@
                 // because the data should be static anyway.
                 result = new char *[PyList_GET_SIZE(names) + 1];
                 result[PyList_GET_SIZE(names)] = 0;
+
+                sipRes = result;
         
                 for (SIP_SSIZE_T i = 0; i < PyList_GET_SIZE(names); ++i)
                 {


More information about the PyQt mailing list