Skip to content

Commit

Permalink
properly close the serial line on error
Browse files Browse the repository at this point in the history
  • Loading branch information
arska committed Feb 5, 2016
1 parent 47f9f1b commit 3d015fb
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bin/mbus-serial-scan-secondary.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,17 @@ main(int argc, char **argv)
if (mbus_connect(handle) == -1)
{
fprintf(stderr,"Failed to setup connection to M-bus gateway\n");
mbus_disconnect(handle);
mbus_context_free(handle);
free(addr_mask);
return 1;
}

if (mbus_serial_set_baudrate(handle, baudrate) == -1)
{
fprintf(stderr, "Failed to set baud rate.\n");
mbus_disconnect(handle);
mbus_context_free(handle);
free(addr_mask);
return 1;
}
Expand All @@ -132,6 +136,8 @@ main(int argc, char **argv)
if (frame == NULL)
{
fprintf(stderr, "Failed to allocate mbus frame.\n");
mbus_disconnect(handle);
mbus_context_free(handle);
free(addr_mask);
return 1;
}
Expand Down

0 comments on commit 3d015fb

Please sign in to comment.