python plugin: fix building with python 3
[collectd.git] / src / python.c
index 4d294dd..b991f45 100644 (file)
@@ -1132,12 +1132,16 @@ static int cpy_config(oconfig_item_t *ci) {
 #ifdef IS_PY3K
                        ERROR("python: \"Encoding\" was used in the config file but Python3 was used, which does not support changing encodings");
                        status = 1;
+                       sfree(encoding);
+                       continue;
 #else
                        /* Why is this even necessary? And undocumented? */
-                       if (PyUnicode_SetDefaultEncoding(encoding))
+                       if (PyUnicode_SetDefaultEncoding(encoding)) {
                                cpy_log_exception("setting default encoding");
-                       sfree(encoding);
+                               status = 1;
+                       }
 #endif
+                       sfree(encoding);
                } else if (strcasecmp(item->key, "LogTraces") == 0) {
                        _Bool log_traces;
                        if (cf_util_get_boolean(item, &log_traces) != 0) {