From 560f19f162529d691619ac69ed032321c7f5f1fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Wed, 7 Jun 2017 20:35:54 +0400 Subject: object: fix potential leak in getters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the property is not of the requested type, the getters will leak a QObject. Signed-off-by: Marc-André Lureau Reviewed-by: Eric Blake Reviewed-by: Markus Armbruster Message-Id: <20170607163635.17635-3-marcandre.lureau@redhat.com> Signed-off-by: Markus Armbruster --- qom/object.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'qom/object.c') diff --git a/qom/object.c b/qom/object.c index eb4bc92..c7b8079 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1122,7 +1122,7 @@ char *object_property_get_str(Object *obj, const char *name, retval = g_strdup(qstring_get_str(qstring)); } - QDECREF(qstring); + qobject_decref(ret); return retval; } @@ -1183,7 +1183,7 @@ bool object_property_get_bool(Object *obj, const char *name, retval = qbool_get_bool(qbool); } - QDECREF(qbool); + qobject_decref(ret); return retval; } @@ -1214,7 +1214,7 @@ int64_t object_property_get_int(Object *obj, const char *name, retval = qint_get_int(qint); } - QDECREF(qint); + qobject_decref(ret); return retval; } -- cgit v1.1 From 01b2ffcedd94ad7b42bc870e4c6936c87ad03429 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Wed, 7 Jun 2017 20:35:58 +0400 Subject: qapi: merge QInt and QFloat in QNum MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We would like to use a same QObject type to represent numbers, whether they are int, uint, or floats. Getters will allow some compatibility between the various types if the number fits other representations. Add a few more tests while at it. Signed-off-by: Marc-André Lureau Message-Id: <20170607163635.17635-7-marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster [parse_stats_intervals() simplified a bit, comment in test_visitor_in_int_overflow() tidied up, suppress bogus warnings] Signed-off-by: Markus Armbruster --- qom/object.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'qom/object.c') diff --git a/qom/object.c b/qom/object.c index c7b8079..dee7f7c 100644 --- a/qom/object.c +++ b/qom/object.c @@ -27,7 +27,6 @@ #include "qom/qom-qobject.h" #include "qapi/qmp/qobject.h" #include "qapi/qmp/qbool.h" -#include "qapi/qmp/qint.h" #include "qapi/qmp/qstring.h" #define MAX_INTERFACES 32 @@ -1190,28 +1189,27 @@ bool object_property_get_bool(Object *obj, const char *name, void object_property_set_int(Object *obj, int64_t value, const char *name, Error **errp) { - QInt *qint = qint_from_int(value); - object_property_set_qobject(obj, QOBJECT(qint), name, errp); + QNum *qnum = qnum_from_int(value); + object_property_set_qobject(obj, QOBJECT(qnum), name, errp); - QDECREF(qint); + QDECREF(qnum); } int64_t object_property_get_int(Object *obj, const char *name, Error **errp) { QObject *ret = object_property_get_qobject(obj, name, errp); - QInt *qint; + QNum *qnum; int64_t retval; if (!ret) { return -1; } - qint = qobject_to_qint(ret); - if (!qint) { + + qnum = qobject_to_qnum(ret); + if (!qnum || !qnum_get_try_int(qnum, &retval)) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name, "int"); retval = -1; - } else { - retval = qint_get_int(qint); } qobject_decref(ret); -- cgit v1.1 From 3152779cd63ba41331ef41659406f65b03e7911a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Wed, 7 Jun 2017 20:36:04 +0400 Subject: object: add uint property setter/getter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc-André Lureau Reviewed-by: Markus Armbruster Message-Id: <20170607163635.17635-13-marcandre.lureau@redhat.com> Signed-off-by: Markus Armbruster --- qom/object.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'qom/object.c') diff --git a/qom/object.c b/qom/object.c index dee7f7c..5f6fdfa 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1216,6 +1216,35 @@ int64_t object_property_get_int(Object *obj, const char *name, return retval; } +void object_property_set_uint(Object *obj, uint64_t value, + const char *name, Error **errp) +{ + QNum *qnum = qnum_from_uint(value); + + object_property_set_qobject(obj, QOBJECT(qnum), name, errp); + QDECREF(qnum); +} + +uint64_t object_property_get_uint(Object *obj, const char *name, + Error **errp) +{ + QObject *ret = object_property_get_qobject(obj, name, errp); + QNum *qnum; + uint64_t retval; + + if (!ret) { + return 0; + } + qnum = qobject_to_qnum(ret); + if (!qnum || !qnum_get_try_uint(qnum, &retval)) { + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name, "uint"); + retval = 0; + } + + qobject_decref(ret); + return retval; +} + typedef struct EnumProperty { const char * const *strings; int (*get)(Object *, Error **); -- cgit v1.1