fuzzers: init Python in LLVMFuzzerInitialize and intentionally leak it
authorAugie Fackler <augie@google.com>
Mon, 08 Oct 2018 11:47:25 -0400
changeset 40089 3418f83c8874
parent 40088 129bfc7ad2cc
child 40090 a66594c5fad4
fuzzers: init Python in LLVMFuzzerInitialize and intentionally leak it This sidesteps leaks (or "leaks", I'm not sure) in CPython, and lets our fuzzer work. Differential Revision: https://phab.mercurial-scm.org/D4906
contrib/fuzz/manifest.cc
--- a/contrib/fuzz/manifest.cc	Mon Oct 08 11:42:06 2018 -0400
+++ b/contrib/fuzz/manifest.cc	Mon Oct 08 11:47:25 2018 -0400
@@ -31,12 +31,12 @@
 	strncpy(cpypath, pypath.c_str(), pypath.size());
 	setenv("PYTHONPATH", cpypath, 1);
 	Py_SetPythonHome(cpypath);
+	Py_InitializeEx(0);
 	return 0;
 }
 
 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
 {
-	Py_InitializeEx(0);
 	initparsers();
 	PyObject *mtext =
 	    PyBytes_FromStringAndSize((const char *)Data, (Py_ssize_t)Size);
@@ -69,7 +69,6 @@
 	Py_DECREF(code);
 	Py_DECREF(locals);
 	Py_DECREF(mtext);
-	Py_Finalize();
 	return 0; // Non-zero return values are reserved for future use.
 }
 }