char cmdline[1024];
struct vsb cmdsb;
char sf[] = "./vcl.########.c";
- char *of;
+ char of[sizeof sf + 1];
+ char *retval;
int p[2], sfd, srclen, status;
pid_t pid;
void *dlh;
AZ(close(sfd));
/* Name the output shared library by overwriting the final 'c' */
- of = strdup(sf);
- XXXAN(of);
- assert(of[sizeof sf - 2] == 'c');
- of[sizeof sf - 2] = 'o';
+ memcpy(of, sf, sizeof sf);
+ assert(sf[sizeof sf - 2] == 'c');
+ of[sizeof sf - 2] = 's';
+ of[sizeof sf - 1] = 'o';
+ of[sizeof sf] = '\0';
AN(vsb_new(&cmdsb, cmdline, sizeof cmdline, 0));
mgt_make_cc_cmd(&cmdsb, sf, of);
vsb_finish(&cmdsb);
vsb_printf(sb, "%s(): pipe() failed: %s",
__func__, strerror(errno));
(void)unlink(sf);
- free(of);
return (NULL);
}
assert(p[0] > STDERR_FILENO);
AZ(close(p[0]));
AZ(close(p[1]));
(void)unlink(sf);
- free(of);
return (NULL);
}
if (pid == 0) {
vsb_printf(sb, "%s(): waitpid() failed: %s",
__func__, strerror(errno));
(void)unlink(of);
- free(of);
return (NULL);
}
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
if (WCOREDUMP(status))
vsb_printf(sb, ", core dumped");
(void)unlink(of);
- free(of);
return (NULL);
}
"%s(): failed to load compiled VCL program:\n %s",
__func__, dlerror());
(void)unlink(of);
- free(of);
return (NULL);
}
*/
AZ(dlclose(dlh));
- return (of);
+ retval = strdup(of);
+ XXXAN(retval);
+ return (retval);
}
/*--------------------------------------------------------------------*/