Patchwork [4,of,7] parsers: handle refcounting of "parents" consistently

login
register
mail settings
Submitter Gregory Szorc
Date March 14, 2017, 5:15 a.m.
Message ID <d600bd4edd62b3ee7473.1489468546@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/19320/
State Accepted
Headers show

Comments

Gregory Szorc - March 14, 2017, 5:15 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1489452553 25200
#      Mon Mar 13 17:49:13 2017 -0700
# Node ID d600bd4edd62b3ee74730f1282e53b9d596bbaec
# Parent  6d3b13f243bea2c9200eecb827d7ec0ea771fc54
parsers: handle refcounting of "parents" consistently

Py_None can be refcounted like any other Python object. So
do that.
Yuya Nishihara - March 16, 2017, 2:24 p.m.
On Mon, 13 Mar 2017 22:15:46 -0700, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1489452553 25200
> #      Mon Mar 13 17:49:13 2017 -0700
> # Node ID d600bd4edd62b3ee74730f1282e53b9d596bbaec
> # Parent  6d3b13f243bea2c9200eecb827d7ec0ea771fc54
> parsers: handle refcounting of "parents" consistently
> 
> Py_None can be refcounted like any other Python object. So
> do that.

Sure, queued this, thanks.

Patch

diff --git a/mercurial/parsers.c b/mercurial/parsers.c
--- a/mercurial/parsers.c
+++ b/mercurial/parsers.c
@@ -2739,6 +2739,7 @@  static PyObject *fm1readmarker(const cha
 		data += nparents * hashwidth;
 	} else {
 		parents = Py_None;
+		Py_INCREF(parents);
 	}
 
 	if (data + 2 * nmetadata > dataend) {
@@ -2781,8 +2782,7 @@  bail:
 	Py_XDECREF(prec);
 	Py_XDECREF(succs);
 	Py_XDECREF(metadata);
-	if (parents != Py_None)
-		Py_XDECREF(parents);
+	Py_XDECREF(parents);
 	return ret;
 }