Mercurial > public > mercurial-scm > hg
comparison mercurial/osutil.c @ 23966:2d2c0a8eeeb8 stable
osutil: fix memory leak of PyBytes of path in statfiles
Spotted with cpychecker.
author | Augie Fackler <augie@google.com> |
---|---|
date | Tue, 27 Jan 2015 10:17:16 -0500 |
parents | 1f3b94e8dc40 |
children | 73477e755cd2 |
comparison
equal
deleted
inserted
replaced
23965:6156edaa82aa | 23966:2d2c0a8eeeb8 |
---|---|
408 stats = PyList_New(count); | 408 stats = PyList_New(count); |
409 if (stats == NULL) | 409 if (stats == NULL) |
410 return NULL; | 410 return NULL; |
411 | 411 |
412 for (i = 0; i < count; i++) { | 412 for (i = 0; i < count; i++) { |
413 PyObject *stat; | 413 PyObject *stat, *pypath; |
414 struct stat st; | 414 struct stat st; |
415 int ret, kind; | 415 int ret, kind; |
416 char *path; | 416 char *path; |
417 | 417 |
418 path = PyString_AsString(PySequence_GetItem(names, i)); | 418 pypath = PySequence_GetItem(names, i); |
419 if (!pypath) | |
420 return NULL; | |
421 path = PyString_AsString(pypath); | |
419 if (path == NULL) { | 422 if (path == NULL) { |
423 Py_DECREF(pypath); | |
420 PyErr_SetString(PyExc_TypeError, "not a string"); | 424 PyErr_SetString(PyExc_TypeError, "not a string"); |
421 goto bail; | 425 goto bail; |
422 } | 426 } |
423 ret = lstat(path, &st); | 427 ret = lstat(path, &st); |
428 Py_DECREF(pypath); | |
424 kind = st.st_mode & S_IFMT; | 429 kind = st.st_mode & S_IFMT; |
425 if (ret != -1 && (kind == S_IFREG || kind == S_IFLNK)) { | 430 if (ret != -1 && (kind == S_IFREG || kind == S_IFLNK)) { |
426 stat = makestat(&st); | 431 stat = makestat(&st); |
427 if (stat == NULL) | 432 if (stat == NULL) |
428 goto bail; | 433 goto bail; |