Skip to content

Commit

Permalink
Free ipc buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
vilhalmer committed Dec 19, 2020
1 parent 166dd8a commit b822c12
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ogurictl.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,19 @@ int main(int argc, char * argv[]) {
}
else {
fprintf(stderr, "Unknown command '%s'\n\n%s", subcommand, usage);
free(buffer);
return 1;
}

if (subcommand_return != 0) {
free(buffer);
return subcommand_return;
}

int sock_fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (sock_fd == -1) {
perror("Unable to create socket");
free(buffer);
return 1;
}

Expand All @@ -151,13 +154,15 @@ int main(int argc, char * argv[]) {
int len = snprintf(remote.sun_path, path_size, "%s/oguri", runtime);
if (path_size <= len) {
fprintf(stderr, "Socket path is too long, unable to connect\n");
free(buffer);
return 1;
}

int connected = connect(
sock_fd, (struct sockaddr *)&remote, sizeof(remote));
if (connected == -1) {
perror("Unable to connect to oguri socket");
free(buffer);
return 1;
}

Expand All @@ -179,10 +184,12 @@ int main(int argc, char * argv[]) {
// oguri had nothing to say.
}

free(buffer);
close(sock_fd);
return 0;

close_err:
free(buffer);
close(sock_fd);
return 1;
}

0 comments on commit b822c12

Please sign in to comment.