Browse Source

Add some decref + update README adding debugging notes

When using the debug build of python, assserts raises en freeze pyfcgi telling
a decref is run on a thing with visit count == 0....
Yann Weber 4 years ago
parent
commit
18a561a7ef
2 changed files with 13 additions and 0 deletions
  1. 6
    0
      README
  2. 7
    0
      src/python_pyfcgi.c

+ 6
- 0
README View File

@@ -16,3 +16,9 @@ or
16 16
 logging to file example :
17 17
 -------------------------
18 18
 -L '/tmp/foo.log;0xff;{datetime} {msg} {ident}'
19
+
20
+Debugging :
21
+-----------
22
+	$ ./configure PYTHON_CONFIG_PATH=/usr/bin/python3dm-config --enable-debug
23
+	$ make clean && make
24
+	$ valgrind --log-file=/tmp/val.log --trace-children=yes spawn-fcgi -d . -n -p 9000 -a 127.0.0.1 -- src/pyfcgi -S -e foo_pep333 -E entrypoint -L '/tmp/foo.log;0xff;{datetime} {msg} {ident}'

+ 7
- 0
src/python_pyfcgi.c View File

@@ -124,6 +124,7 @@ void libpyfcgi_set_headers_buf()
124 124
 	}
125 125
 
126 126
 repr = PyObject_ASCII(libpyfcgi.headers);
127
+Py_INCREF(repr);
127 128
 pyfcgi_log(LOG_DEBUG, "Sending headers : '%s'", PyUnicode_AsUTF8(repr));
128 129
 Py_DECREF(repr);
129 130
 
@@ -134,6 +135,7 @@ Py_DECREF(repr);
134 135
 		pyfcgi_log(LOG_ERR, "Unable to get iterator from given headers");
135 136
 		return;
136 137
 	}
138
+	Py_INCREF(heads_iter);
137 139
 
138 140
 	n_head = 0;
139 141
 	buf_ptr = libpyfcgi.heads_buf; //buffer pointer
@@ -142,10 +144,12 @@ Py_DECREF(repr);
142 144
 	buf_off = 0; //buffer pointer offset
143 145
 	while((head_tuple = PyIter_Next(heads_iter)))
144 146
 	{
147
+		Py_INCREF(head_tuple);
145 148
 		head_seq = PySequence_Fast(head_tuple, "Headers element is not a sequence");
146 149
 		if((tsz = PySequence_Fast_GET_SIZE(head_seq)) != 2)
147 150
 		{
148 151
 			repr = PyObject_ASCII(head_tuple);
152
+			Py_INCREF(repr);
149 153
 			snprintf(errstr, 256,
150 154
 				"Headers element expected to have len == 2, but got len %ld for element %ld : %s", tsz, n_head, PyUnicode_AsUTF8(repr));
151 155
 			Py_DECREF(repr);
@@ -174,6 +178,7 @@ Py_DECREF(repr);
174 178
 					goto head_decode_err;
175 179
 				}
176 180
 			}
181
+			Py_INCREF(bytes[i]);
177 182
 			head_str[i] = PyBytes_AsString(bytes[i]);
178 183
 			
179 184
 		}
@@ -210,6 +215,8 @@ Py_DECREF(repr);
210 215
 		}
211 216
 
212 217
 		n_head++;
218
+		Py_DECREF(bytes[0]);
219
+		Py_DECREF(bytes[1]);
213 220
 		Py_DECREF(head_seq);
214 221
 		Py_DECREF(head_tuple);
215 222
 	}

Loading…
Cancel
Save