summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
inline | side by side (from parent 1:
878e90d)
Avoid plain malloc()/free() in sr/srd, especially in the API calls.
Also avoid g_malloc*() in favor of g_try_malloc*().
Use g_strdup() instead of strdup() so that we can use g_free()
consistently everywhere.
Exceptions: Stuff that is allocated via other libs (not using glib),
should also be properly free'd using the respective free-ing function
(instead of g_free()). Examples: Stuff allocated by libusb, libftdi, etc.
Also, use sr_err() instead of sr_warn() for actual errors. sr_warn() is
meant for non-fatal/uncritical warnings.
error = FALSE;
range = NULL;
error = FALSE;
range = NULL;
- probelist = g_malloc0(max_probes * sizeof(char *));
+ if (!(probelist = g_try_malloc0(max_probes * sizeof(char *)))) {
+ /* TODO: Handle errors. */
+ }
tokens = g_strsplit(probestring, ",", max_probes);
for (i = 0; tokens[i]; i++) {
tokens = g_strsplit(probestring, ",", max_probes);
for (i = 0; tokens[i]; i++) {
if (!(s = sr_samplerate_string(samplerates->low)))
continue;
printf(" (%s", s);
if (!(s = sr_samplerate_string(samplerates->low)))
continue;
printf(" (%s", s);
/* high */
if (!(s = sr_samplerate_string(samplerates->high)))
continue;
printf(" - %s", s);
/* high */
if (!(s = sr_samplerate_string(samplerates->high)))
continue;
printf(" - %s", s);
/* step */
if (!(s = sr_samplerate_string(samplerates->step)))
continue;
printf(" in steps of %s)\n", s);
/* step */
if (!(s = sr_samplerate_string(samplerates->step)))
continue;
printf(" in steps of %s)\n", s);
} else {
printf(" - supported samplerates:\n");
for (i = 0; samplerates->list[i]; i++) {
} else {
printf(" - supported samplerates:\n");
for (i = 0; samplerates->list[i]; i++) {
case SR_DF_HEADER:
g_message("cli: Received SR_DF_HEADER");
/* Initialize the output module. */
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);
}
printf("Output module malloc failed.\n");
exit(1);
}
if (output_len) {
if (outfile)
fwrite(output_buf, 1, output_len, outfile);
if (output_len) {
if (outfile)
fwrite(output_buf, 1, output_len, outfile);
sr_session_halt();
if (outfile && outfile != stdout)
fclose(outfile);
sr_session_halt();
if (outfile && outfile != stdout)
fclose(outfile);
o = NULL;
break;
case SR_DF_TRIGGER:
o = NULL;
break;
case SR_DF_TRIGGER:
o->format->data(o, filter_out, filter_out_len, &output_buf, &output_len);
if (output_len) {
fwrite(output_buf, 1, output_len, outfile);
o->format->data(o, filter_out, filter_out_len, &output_buf, &output_len);
if (output_len) {
fwrite(output_buf, 1, output_len, outfile);
}
/* Initialize the input module. */
}
/* 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);
}
printf("Failed to allocate input module.\n");
exit(1);
}