question about reference counts in code generated by pidl

Julia Lawall julia.lawall at lip6.fr
Sun Jun 3 14:27:48 MDT 2012


pidl generated code seems to contains lots of memory allocations, 
especially calls to PyTuple_New, with no corresponding decrefs on failure.

One example is (sources.debian.org/sources/main/s/samba/2:3.6.5-3/sam\
ba-3.6.5/source3/librpc/gen_ndr/py_spoolss.c, function 
unpack_py_spoolss_EnumPrinters_args_out):

         result = PyTuple_New(3);
         py_count = PyInt_FromLong(*r->out.count);
         PyTuple_SetItem(result, 0, py_count);
         if (*r->out.info == NULL) {
                 py_info = Py_None;
                 Py_INCREF(py_info);
         } else {
                 py_info = PyList_New(*r->out.count);
                 if (py_info == NULL) {
                         return NULL;
                 }
                 {
                         int info_cntr_2;
                         for (info_cntr_2 = 0; info_cntr_2 < *r->out.count; 
info_cntr_2++) {
                                 PyObject *py_info_2;
                                 py_info_2 = py_import_spoolss_PrinterInfo(*r->out.info, r->in.level, r->out.info[info_cntr_2]);
                                 if (py_info_2 == NULL) {
                                         return NULL;
         	                }
                                 PyList_SetItem(py_info, info_cntr_2, py_info_2);
                         }
                 }
         }

This example is a bit long, but I picked it because it also has a call to 
PyList_New that has the same problem (line 8).

There is also no check whether PyTuple_New has failed.

The rest of the same function is:

         PyTuple_SetItem(result, 1, py_info);
         py_needed = PyInt_FromLong(*r->out.needed);
         PyTuple_SetItem(result, 2, py_needed);
         if (!W_ERROR_IS_OK(r->out.result)) {
                 PyErr_SetWERROR(r->out.result);
                 return NULL;
         }

         return result;

So it seems that another failure can occur after the result value has been 
all set up, in which case the result value is again ignored.

Are these failures very unlikely, and thus not worth bothering about?

At least in this case, it seems like a solution could be to just move all 
of the tests before the allocation and initialization of the result.  The 
result does not seem to be used in any of the tests.

thanks,
julia


More information about the samba-technical mailing list