Mercurial > public > mercurial-scm > hg
comparison mercurial/osutil.c @ 23962:1f3b94e8dc40 stable
osutil: fix leak of stat in makestat when Py_BuildValue fails
Spotted with cpychecker.
author | Augie Fackler <augie@google.com> |
---|---|
date | Tue, 27 Jan 2015 10:14:23 -0500 |
parents | bc851e2851b1 |
children | 2d2c0a8eeeb8 |
comparison
equal
deleted
inserted
replaced
23961:bc851e2851b1 | 23962:1f3b94e8dc40 |
---|---|
286 return stat; | 286 return stat; |
287 } | 287 } |
288 | 288 |
289 static PyObject *_listdir(char *path, int pathlen, int keepstat, char *skip) | 289 static PyObject *_listdir(char *path, int pathlen, int keepstat, char *skip) |
290 { | 290 { |
291 PyObject *list, *elem, *stat, *ret = NULL; | 291 PyObject *list, *elem, *stat = NULL, *ret = NULL; |
292 char fullpath[PATH_MAX + 10]; | 292 char fullpath[PATH_MAX + 10]; |
293 int kind, err; | 293 int kind, err; |
294 struct stat st; | 294 struct stat st; |
295 struct dirent *ent; | 295 struct dirent *ent; |
296 DIR *dir; | 296 DIR *dir; |
367 elem = Py_BuildValue("siN", ent->d_name, kind, stat); | 367 elem = Py_BuildValue("siN", ent->d_name, kind, stat); |
368 } else | 368 } else |
369 elem = Py_BuildValue("si", ent->d_name, kind); | 369 elem = Py_BuildValue("si", ent->d_name, kind); |
370 if (!elem) | 370 if (!elem) |
371 goto error; | 371 goto error; |
372 stat = NULL; | |
372 | 373 |
373 PyList_Append(list, elem); | 374 PyList_Append(list, elem); |
374 Py_DECREF(elem); | 375 Py_DECREF(elem); |
375 } | 376 } |
376 | 377 |
377 ret = list; | 378 ret = list; |
378 Py_INCREF(ret); | 379 Py_INCREF(ret); |
379 | 380 |
380 error: | 381 error: |
381 Py_DECREF(list); | 382 Py_DECREF(list); |
383 Py_XDECREF(stat); | |
382 error_list: | 384 error_list: |
383 closedir(dir); | 385 closedir(dir); |
384 error_dir: | 386 error_dir: |
385 #ifdef AT_SYMLINK_NOFOLLOW | 387 #ifdef AT_SYMLINK_NOFOLLOW |
386 close(dfd); | 388 close(dfd); |