Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b399ab2

Browse files
committed
clean up converted path on error
1 parent 3e2e368 commit b399ab2

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

Modules/posixmodule.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3695,7 +3695,7 @@ utime_read_time_arguments(utime_arguments *ua)
36953695
"%s: you may specify either 'times'"
36963696
" or 'ns' but not both",
36973697
ua->function_name);
3698-
return 0;
3698+
goto fail;
36993699
}
37003700

37013701
if (times && (times != Py_None)) {
@@ -3704,32 +3704,41 @@ utime_read_time_arguments(utime_arguments *ua)
37043704
"%s: 'time' must be either"
37053705
" a valid tuple of two ints or None",
37063706
ua->function_name);
3707-
return 0;
3707+
goto fail;
37083708
}
37093709
ua->now = 0;
3710-
return (_PyTime_ObjectToTimespec(PyTuple_GET_ITEM(times, 0),
3711-
&(ua->atime_s), &(ua->atime_ns)) != -1)
3712-
&& (_PyTime_ObjectToTimespec(PyTuple_GET_ITEM(times, 1),
3713-
&(ua->mtime_s), &(ua->mtime_ns)) != -1);
3710+
if (_PyTime_ObjectToTimespec(PyTuple_GET_ITEM(times, 0),
3711+
&ua->atime_s, &ua->atime_ns) == -1 ||
3712+
_PyTime_ObjectToTimespec(PyTuple_GET_ITEM(times, 1),
3713+
&ua->mtime_s, &ua->mtime_ns) == -1)
3714+
goto fail;
3715+
return 1;
37143716
}
37153717

37163718
if (ns) {
37173719
if (!PyTuple_CheckExact(ns) || (PyTuple_Size(ns) != 2)) {
37183720
PyErr_Format(PyExc_TypeError,
37193721
"%s: 'ns' must be a valid tuple of two ints",
37203722
ua->function_name);
3721-
return 0;
3723+
goto fail;
37223724
}
37233725
ua->now = 0;
3724-
return (split_py_long_to_s_and_ns(PyTuple_GET_ITEM(ns, 0),
3725-
&(ua->atime_s), &(ua->atime_ns)))
3726-
&& (split_py_long_to_s_and_ns(PyTuple_GET_ITEM(ns, 1),
3727-
&(ua->mtime_s), &(ua->mtime_ns)));
3726+
if (!split_py_long_to_s_and_ns(PyTuple_GET_ITEM(ns, 0),
3727+
&ua->atime_s, &ua->atime_ns) ||
3728+
!split_py_long_to_s_and_ns(PyTuple_GET_ITEM(ns, 1),
3729+
&ua->mtime_s, &ua->mtime_ns))
3730+
goto fail;
3731+
return 1;
37283732
}
37293733

37303734
/* either times=None, or neither times nor ns was specified. use "now". */
37313735
ua->now = 1;
37323736
return 1;
3737+
3738+
fail:
3739+
if (ua->converter)
3740+
Py_DECREF(ua->path);
3741+
return 0;
37333742
}
37343743

37353744

0 commit comments

Comments
 (0)