libsigrok.git commit
b8072700c1bc7d13ba004fd897668b56cec4ac62 adds
struct sr_context to the public API, and changes sr_init() and sr_exit()
to take a struct sr_context ** and struct sr_context * parameter,
respectively.
struct sr_context is opaque, and all sr_init() and sr_exit() calls must
be balanced.
Thanks to the new struct sr_context * the error path code flow can also
be simplifed, and allow a single point in main() to clean up after any
possible program state.
int ret = 1;
GOptionContext *context;
GError *error;
int ret = 1;
GOptionContext *context;
GError *error;
+ struct sr_context *sr_ctx = NULL;
g_log_set_default_handler(logger, NULL);
g_log_set_default_handler(logger, NULL);
if (!g_option_context_parse(context, &argc, &argv, &error)) {
g_critical("%s", error->message);
if (!g_option_context_parse(context, &argc, &argv, &error)) {
g_critical("%s", error->message);
}
/* Set the loglevel (amount of messages to output) for libsigrok. */
if (sr_log_loglevel_set(opt_loglevel) != SR_OK)
}
/* Set the loglevel (amount of messages to output) for libsigrok. */
if (sr_log_loglevel_set(opt_loglevel) != SR_OK)
/* Set the loglevel (amount of messages to output) for libsigrokdecode. */
if (srd_log_loglevel_set(opt_loglevel) != SRD_OK)
/* Set the loglevel (amount of messages to output) for libsigrokdecode. */
if (srd_log_loglevel_set(opt_loglevel) != SRD_OK)
- if (sr_init() != SR_OK)
- goto done_noexit;
+ if (sr_init(&sr_ctx) != SR_OK)
+ goto done;
if (opt_pds) {
if (srd_init(NULL) != SRD_OK)
if (opt_pds) {
if (srd_init(NULL) != SRD_OK)
+ if (sr_ctx)
+ sr_exit(sr_ctx);
g_option_context_free(context);
return ret;
g_option_context_free(context);
return ret;