800 static PyObject *
801 pylistxattr(PyObject *self, PyObject *args)
802 {
803 char *buf;
804 int nofollow=0;
805 ssize_t nalloc, nret;
806 PyObject *myarg;
807 PyObject *mylist;
808 Py_ssize_t nattrs;
809 char *s;
810 target_t tgt;
811
812 /* Parse the arguments */
813 if (!PyArg_ParseTuple(args, "O|i", &myarg, &nofollow))
when _PyArg_ParseTuple_SizeT() succeeds
taking False path
814 return NULL;
815 if(!convertObj(myarg, &tgt, nofollow))
when considering range: -0x80000000 <= value <= -1
taking False path
816 return NULL;
817
818 /* Find out the needed size of the buffer */
819 if((nalloc = _list_obj(&tgt, NULL, 0)) == -1) {
when considering range: -0x8000000000000000 <= value <= -2
taking False path
820 mylist = PyErr_SetFromErrno(PyExc_IOError);
821 goto freetgt;
822 }
823
824 /* Try to allocate the memory, using Python's allocator */
825 if((buf = PyMem_Malloc(nalloc)) == NULL) {
when PyMem_Malloc() succeeds
taking False path
826 mylist = PyErr_NoMemory();
827 goto freetgt;
828 }
829
830 /* Now retrieve the list of attributes */
831 if((nret = _list_obj(&tgt, buf, nalloc)) == -1) {
when considering range: -0x8000000000000000 <= value <= -2
taking False path
832 mylist = PyErr_SetFromErrno(PyExc_IOError);
833 goto freebuf;
834 }
835
836 /* Compute the number of attributes in the list */
837 for(s = buf, nattrs = 0; (s - buf) < nret; s += strlen(s) + 1) {
when taking True path
when taking False path
838 nattrs++;
839 }
840
841 /* Create the list which will hold the result */
842 mylist = PyList_New(nattrs);
when PyList_New() fails
843
844 /* Create and insert the attributes as strings in the list */
845 for(s = buf, nattrs = 0; s - buf < nret; s += strlen(s) + 1) {
when taking True path
846 PyList_SET_ITEM(mylist, nattrs, PyBytes_FromString(s));
dereferencing NULL (MEM[(struct PyListObject *)mylist].ob_item) at xattr.c:846
found 1 similar trace(s) to this
847 nattrs++;
848 }
849
850 freebuf:
851 /* Free the buffer, now it is no longer needed */
852 PyMem_Free(buf);
853
854 freetgt:
855 free_tgt(&tgt);
856
857 /* Return the result */
858 return mylist;
859 }