From 57812edf81a62d0b8a49a2399ee26c9e611c65e2 Mon Sep 17 00:00:00 2001 From: "Mytnyk, VolodymyrX" Date: Mon, 6 Feb 2017 11:28:33 +0000 Subject: [PATCH] python: Fix python plugin crash If python pugin reads and writes collectd values, the write python plugin callback may crash (90%) on free table var (line 478) if the meta data structure is created but no information is present there. It's possible to reproduce it due to changes introduced by #2135 PR. cpy_write_callback(): ... 425 if (value_list->meta) { 426 char **table; 427 meta_data_t *meta = value_list->meta; 428 429 int num = meta_data_toc(meta, &table); 430 for (int i = 0; i < num; ++i) { ... 477 } 478 free(table); 479 } Change-Id: Ic897933f447b9280f266b6e78b6b73bd12182eba Signed-off-by: Mytnyk, VolodymyrX --- src/python.c | 2 +- src/pyvalues.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/python.c b/src/python.c index d4efa94d..a8f5177f 100644 --- a/src/python.c +++ b/src/python.c @@ -423,7 +423,7 @@ static int cpy_write_callback(const data_set_t *ds, } dict = PyDict_New(); /* New reference. */ if (value_list->meta) { - char **table; + char **table = NULL; meta_data_t *meta = value_list->meta; int num = meta_data_toc(meta, &table); diff --git a/src/pyvalues.c b/src/pyvalues.c index 9c8809da..5dcdf6a2 100644 --- a/src/pyvalues.c +++ b/src/pyvalues.c @@ -576,7 +576,10 @@ CPY_BUILD_META_HANDLER(plugin_notification_meta, notification_t); static meta_data_t *cpy_build_value_meta(PyObject *meta) { meta_data_t *m = meta_data_create(); - cpy_build_meta(meta, &cpy_meta_data, (void *)m); + if (cpy_build_meta(meta, &cpy_meta_data, (void *)m) < 0) { + meta_data_destroy(m); + return NULL; + } return m; } -- 2.11.0