diff --git a/src/python/pmapi.c b/src/python/pmapi.c index 715d634..b1eb53d 100644 --- a/src/python/pmapi.c +++ b/src/python/pmapi.c @@ -595,7 +595,16 @@ getOptionsFromList(PyObject *self, PyObject *args, PyObject *keywords) for (i = 0; i < argc; i++) { PyObject *pyarg = PyList_GET_ITEM(pyargv, i); - argv[i] = PyString_AsString(pyarg); + char *string = PyString_AsString(pyarg); + + /* argv[0] parameter will be used for pmProgname, so need to + * ensure the memory that backs it will be with us forever. + */ + if (argc == 0 && (string = strdup(string)) == NULL) { + Py_DECREF(pyargv); + return PyErr_NoMemory(); + } + argv[i] = string; } if (overridesCallback)