static void unlink_object(const char *path)
{
- TALLOC_CTX *mem_ctx = talloc_new(NULL);
- char *cmd;
+ char *rmcmd = NULL;
int ret;
struct stat st;
ret = lstat(path, &st);
if ((ret == -1) && (errno == ENOENT)) {
errno = 0;
- talloc_free(mem_ctx);
return;
}
if ( (st.st_mode & S_IFMT) == S_IFREG) {
unlink(path);
- talloc_free(mem_ctx);
return;
}
- cmd = talloc_asprintf(mem_ctx, "rm -rf %s", path);
- ret = system(cmd);
+ if (asprintf(&rmcmd, "rm -rf %s", path)) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc rmcmd\n"));
+ goto finished;
+ }
+ ret = system(rmcmd);
if (ret != 0) {
- DEBUG(DEBUG_DEBUG,("%s failed with ret:%d\n", cmd, ret));
+ DEBUG(DEBUG_DEBUG,("%s failed with ret:%d\n", rmcmd, ret));
+ }
+
+finished:
+ if (rmcmd != NULL) {
+ free(rmcmd);
}
- talloc_free(mem_ctx);
}