chiark / gitweb /
systemd-python: check for oom, give nicer error messages
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 15 Aug 2013 16:51:20 +0000 (12:51 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 15 Aug 2013 16:59:36 +0000 (12:59 -0400)
src/python-systemd/_reader.c
src/python-systemd/login.c

index 3b1003ba71f99e5a621ac622b7ab7a370947d607..bc5db19049577d079bba9db08bd3269d2d164597 100644 (file)
@@ -75,7 +75,7 @@ static int strv_converter(PyObject* obj, void *_result) {
         assert(result);
 
         if (!obj)
-            goto cleanup;
+            return 0;
 
         if (obj == Py_None) {
             *result = NULL;
@@ -87,6 +87,10 @@ static int strv_converter(PyObject* obj, void *_result) {
 
         len = PySequence_Length(obj);
         *result = new0(char*, len + 1);
+        if (!*result) {
+            set_error(-ENOMEM, NULL, NULL);
+            return 0;
+        }
 
         for (i = 0; i < len; i++) {
             PyObject *item;
@@ -154,7 +158,7 @@ static int Reader_init(Reader *self, PyObject *args, PyObject *keywds)
     char **files = NULL;
 
     static const char* const kwlist[] = {"flags", "path", "files", NULL};
-    if (!PyArg_ParseTupleAndKeywords(args, keywds, "|izO&", (char**) kwlist,
+    if (!PyArg_ParseTupleAndKeywords(args, keywds, "|izO&:__init__", (char**) kwlist,
                                      &flags, &path, strv_converter, &files))
         return -1;
 
index 1e86193f6be8f3a6ca29838ee6e53acfb4627e2a..dd2edbca00598daaeb2fb2479fcab6a4e0c6138a 100644 (file)
@@ -159,7 +159,7 @@ static int Monitor_init(Monitor *self, PyObject *args, PyObject *keywds)
         int r;
 
         static const char* const kwlist[] = {"category", NULL};
-        if (!PyArg_ParseTupleAndKeywords(args, keywds, "|z", (char**) kwlist,
+        if (!PyArg_ParseTupleAndKeywords(args, keywds, "|z:__init__", (char**) kwlist,
                                          &category))
                 return -1;