Patchwork [2,of,6,cpychecker] parsers: correctly decref normed value after PyDict_SetItem

login
register
mail settings
Submitter Augie Fackler
Date Aug. 18, 2015, 9:54 p.m.
Message ID <f47c42732b0a684119f9.1439934852@arthedain.pit.corp.google.com>
Download mbox | patch
Permalink /patch/10235/
State Accepted
Headers show

Comments

Augie Fackler - Aug. 18, 2015, 9:54 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1439930606 14400
#      Tue Aug 18 16:43:26 2015 -0400
# Node ID f47c42732b0a684119f99fde44f372ffe7380dcb
# Parent  f8fda0f125089c01049651d26fcd955200a02663
parsers: correctly decref normed value after PyDict_SetItem

Previously we were leaving this PyObject* with a refcount that was one
too high. Detected with cpychecker.

Patch

diff --git a/mercurial/parsers.c b/mercurial/parsers.c
--- a/mercurial/parsers.c
+++ b/mercurial/parsers.c
@@ -253,8 +253,11 @@  static PyObject *make_file_foldmap(PyObj
 
 			if (normed == NULL)
 				goto quit;
-			if (PyDict_SetItem(file_foldmap, normed, k) == -1)
+			if (PyDict_SetItem(file_foldmap, normed, k) == -1) {
+				Py_DECREF(normed);
 				goto quit;
+			}
+			Py_DECREF(normed);
 		}
 	}
 	return file_foldmap;