X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fstd.c;h=55952240fefe94e018e4a6b654477c0eab4b220f;hb=27d44cf6e0eaaa75979510596d6148193a8434c0;hp=fed47febe3598e15468b0e2433b6decbd362fb48;hpb=7aebe22d107df4548700bef900be66971658fcac;p=libsigrok.git diff --git a/src/std.c b/src/std.c index fed47feb..55952240 100644 --- a/src/std.c +++ b/src/std.c @@ -23,9 +23,11 @@ * @internal */ +#include #include -#include "libsigrok.h" +#include #include "libsigrok-internal.h" +#include "scpi.h" #define LOG_PREFIX "std" @@ -41,8 +43,7 @@ * @param di The driver instance to use. * @param[in] prefix A driver-specific prefix string used for log messages. * - * @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, or - * SR_ERR_MALLOC upon memory allocation errors. + * @return SR_OK upon success, SR_ERR_ARG upon invalid arguments. */ SR_PRIV int std_init(struct sr_context *sr_ctx, struct sr_dev_driver *di, const char *prefix) @@ -54,14 +55,10 @@ SR_PRIV int std_init(struct sr_context *sr_ctx, struct sr_dev_driver *di, return SR_ERR_ARG; } - if (!(drvc = g_try_malloc(sizeof(struct drv_context)))) { - sr_err("%s: Driver context malloc failed.", prefix); - return SR_ERR_MALLOC; - } - + drvc = g_malloc0(sizeof(struct drv_context)); drvc->sr_ctx = sr_ctx; drvc->instances = NULL; - di->priv = drvc; + di->context = drvc; return SR_OK; } @@ -252,7 +249,7 @@ SR_PRIV int std_dev_clear(const struct sr_dev_driver *driver, GSList *l; int ret; - if (!(drvc = driver->priv)) + if (!(drvc = driver->context)) /* Driver was never initialized, nothing to do. */ return SR_OK; @@ -276,6 +273,8 @@ SR_PRIV int std_dev_clear(const struct sr_dev_driver *driver, #endif if (sdi->inst_type == SR_INST_SCPI) sr_scpi_free(sdi->conn); + if (sdi->inst_type == SR_INST_MODBUS) + sr_modbus_free(sdi->conn); } if (clear_private) /* The helper function is responsible for freeing