X-Git-Url: https://sigrok.org/gitweb/?p=sigrok-cli.git;a=blobdiff_plain;f=sigrok-cli.c;h=fc6884be07b349df565b2bd1d6382394df7d9e55;hp=d51c893ebbc10fe58e6f28aebc06da4fe35a1ff7;hb=7cb9889f780a78f728c10717625e288a20ea69cb;hpb=878e90d9779a1881840454e2ad7bd90a4b470221 diff --git a/sigrok-cli.c b/sigrok-cli.c index d51c893..fc6884b 100644 --- a/sigrok-cli.c +++ b/sigrok-cli.c @@ -234,17 +234,17 @@ static void show_device_detail(void) if (!(s = sr_samplerate_string(samplerates->low))) continue; printf(" (%s", s); - free(s); + g_free(s); /* high */ if (!(s = sr_samplerate_string(samplerates->high))) continue; printf(" - %s", s); - free(s); + g_free(s); /* step */ if (!(s = sr_samplerate_string(samplerates->step))) continue; printf(" in steps of %s)\n", s); - free(s); + g_free(s); } else { printf(" - supported samplerates:\n"); for (i = 0; samplerates->list[i]; i++) { @@ -313,7 +313,7 @@ static void datafeed_in(struct sr_device *device, struct sr_datafeed_packet *pac case SR_DF_HEADER: g_message("cli: Received SR_DF_HEADER"); /* Initialize the output module. */ - if (!(o = malloc(sizeof(struct sr_output)))) { + if (!(o = g_try_malloc(sizeof(struct sr_output)))) { printf("Output module malloc failed.\n"); exit(1); } @@ -370,7 +370,7 @@ static void datafeed_in(struct sr_device *device, struct sr_datafeed_packet *pac if (output_len) { if (outfile) fwrite(output_buf, 1, output_len, outfile); - free(output_buf); + g_free(output_buf); output_len = 0; } } @@ -383,7 +383,7 @@ static void datafeed_in(struct sr_device *device, struct sr_datafeed_packet *pac sr_session_halt(); if (outfile && outfile != stdout) fclose(outfile); - free(o); + g_free(o); o = NULL; break; case SR_DF_TRIGGER: @@ -447,7 +447,7 @@ static void datafeed_in(struct sr_device *device, struct sr_datafeed_packet *pac o->format->data(o, filter_out, filter_out_len, &output_buf, &output_len); if (output_len) { fwrite(output_buf, 1, output_len, outfile); - free(output_buf); + g_free(output_buf); } } @@ -510,11 +510,14 @@ err_out: return 0; } -void show_pd_annotation(struct srd_proto_data *pdata) +void show_pd_annotation(struct srd_proto_data *pdata, void *data) { int i; char **annotations; + /* 'data' is not used in this specific callback. */ + (void)data; + if (pdata->ann_format != 0) { /* CLI only shows the default annotation format. */ return; @@ -646,7 +649,7 @@ static void load_input_file_format(void) } /* Initialize the input module. */ - if (!(in = malloc(sizeof(struct sr_input)))) { + if (!(in = g_try_malloc(sizeof(struct sr_input)))) { printf("Failed to allocate input module.\n"); exit(1); } @@ -1012,7 +1015,7 @@ int main(int argc, char **argv) return 1; } if (srd_register_callback(SRD_OUTPUT_ANN, - show_pd_annotation) != SRD_OK) { + show_pd_annotation, NULL) != SRD_OK) { printf("Failed to register protocol decoder callback\n"); return 1; }