##// END OF EJS Templates
osutil: fix excessive decref on tuple creation failure in listdir()...
Yuya Nishihara -
r45734:f93a4e3d default
parent child Browse files
Show More
@@ -336,7 +336,7 b' static PyObject *makestat(const struct s'
336 static PyObject *_listdir_stat(char *path, int pathlen, int keepstat,
336 static PyObject *_listdir_stat(char *path, int pathlen, int keepstat,
337 char *skip)
337 char *skip)
338 {
338 {
339 PyObject *list, *elem, *stat = NULL, *ret = NULL;
339 PyObject *list, *elem, *ret = NULL;
340 char fullpath[PATH_MAX + 10];
340 char fullpath[PATH_MAX + 10];
341 int kind, err;
341 int kind, err;
342 struct stat st;
342 struct stat st;
@@ -409,7 +409,7 b' static PyObject *_listdir_stat(char *pat'
409 }
409 }
410
410
411 if (keepstat) {
411 if (keepstat) {
412 stat = makestat(&st);
412 PyObject *stat = makestat(&st);
413 if (!stat)
413 if (!stat)
414 goto error;
414 goto error;
415 elem = Py_BuildValue(PY23("siN", "yiN"), ent->d_name,
415 elem = Py_BuildValue(PY23("siN", "yiN"), ent->d_name,
@@ -419,7 +419,6 b' static PyObject *_listdir_stat(char *pat'
419 kind);
419 kind);
420 if (!elem)
420 if (!elem)
421 goto error;
421 goto error;
422 stat = NULL;
423
422
424 PyList_Append(list, elem);
423 PyList_Append(list, elem);
425 Py_DECREF(elem);
424 Py_DECREF(elem);
@@ -430,7 +429,6 b' static PyObject *_listdir_stat(char *pat'
430
429
431 error:
430 error:
432 Py_DECREF(list);
431 Py_DECREF(list);
433 Py_XDECREF(stat);
434 error_list:
432 error_list:
435 closedir(dir);
433 closedir(dir);
436 /* closedir also closes its dirfd */
434 /* closedir also closes its dirfd */
@@ -480,7 +478,7 b' int attrkind(attrbuf_entry *entry)'
480 static PyObject *_listdir_batch(char *path, int pathlen, int keepstat,
478 static PyObject *_listdir_batch(char *path, int pathlen, int keepstat,
481 char *skip, bool *fallback)
479 char *skip, bool *fallback)
482 {
480 {
483 PyObject *list, *elem, *stat = NULL, *ret = NULL;
481 PyObject *list, *elem, *ret = NULL;
484 int kind, err;
482 int kind, err;
485 unsigned long index;
483 unsigned long index;
486 unsigned int count, old_state, new_state;
484 unsigned int count, old_state, new_state;
@@ -586,6 +584,7 b' static PyObject *_listdir_batch(char *pa'
586 }
584 }
587
585
588 if (keepstat) {
586 if (keepstat) {
587 PyObject *stat = NULL;
589 /* from the getattrlist(2) man page: "Only the
588 /* from the getattrlist(2) man page: "Only the
590 permission bits ... are valid". */
589 permission bits ... are valid". */
591 st.st_mode = (entry->access_mask & ~S_IFMT) | kind;
590 st.st_mode = (entry->access_mask & ~S_IFMT) | kind;
@@ -601,7 +600,6 b' static PyObject *_listdir_batch(char *pa'
601 filename, kind);
600 filename, kind);
602 if (!elem)
601 if (!elem)
603 goto error;
602 goto error;
604 stat = NULL;
605
603
606 PyList_Append(list, elem);
604 PyList_Append(list, elem);
607 Py_DECREF(elem);
605 Py_DECREF(elem);
@@ -615,7 +613,6 b' static PyObject *_listdir_batch(char *pa'
615
613
616 error:
614 error:
617 Py_DECREF(list);
615 Py_DECREF(list);
618 Py_XDECREF(stat);
619 error_dir:
616 error_dir:
620 close(dfd);
617 close(dfd);
621 error_value:
618 error_value:
General Comments 0
You need to be logged in to leave comments. Login now