Skip to content

Commit

Permalink
free a string
Browse files Browse the repository at this point in the history
  • Loading branch information
justanhduc committed Oct 19, 2022
1 parent df8d3a9 commit d804e1e
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static void run_gzip(int fd_out, int fd_in) {
}
}

static void run_child(int fd_send_filename, const char* tmpdir) {
static void run_child(int fd_send_filename, char* tmpdir) {
char *outfname;
char errfname[sizeof outfname + 2]; /* .e */
int namesize;
Expand All @@ -155,13 +155,11 @@ static void run_child(int fd_send_filename, const char* tmpdir) {
/* Prepare path */
int lname;
char *outfname_full;
char *outdir = tmpdir == NULL ? "/tmp" : tmpdir;

if (tmpdir == NULL)
tmpdir = "/tmp";
lname = strlen(tmpdir) + strlen(outfname) + 1 /* \0 */;

lname = strlen(outdir) + strlen(outfname) + 1 /* \0 */;
outfname_full = (char *) malloc(lname);
strcpy(outfname_full, tmpdir);
strcpy(outfname_full, outdir);
strcat(outfname_full, outfname);

/* Prepare the filename */
Expand All @@ -170,6 +168,7 @@ static void run_child(int fd_send_filename, const char* tmpdir) {
write(outfd, cmd, strlen(cmd));
write(outfd, "\n", 2);
free(cmd);
free(tmpdir);
if (command_line.gzip) {
int p[2];
/* We assume that all handles are closed*/
Expand Down Expand Up @@ -241,7 +240,7 @@ int run_job(struct Result *res) {
int pid;
int errorlevel;
int p[2];
const char *tmpdir = get_logdir();
char *tmpdir = get_logdir();

/* For the parent */
/*program_signal(); Still not needed*/
Expand All @@ -262,7 +261,7 @@ int run_job(struct Result *res) {
/* Not reachable, if the 'exec' of the command
* works. Thus, command exists, etc. */
fprintf(stderr, "ts could not run the command\n");
free((char*) tmpdir);
free(tmpdir);
exit(-1);
/* To avoid a compiler warning */
errorlevel = 0;
Expand Down

0 comments on commit d804e1e

Please sign in to comment.