remove the use of talloc from unlink_object()
authorroot <root@rcn1.VSOFS1.COM>
Thu, 19 Mar 2009 03:32:45 +0000 (14:32 +1100)
committerroot <root@rcn1.VSOFS1.COM>
Thu, 19 Mar 2009 03:32:45 +0000 (14:32 +1100)
migrate/remote-cache.c

index 45f2284a8737fcc3e51c1c6c84eff1b75e24b4f3..d6becc679b06e8eadc83b7f37afc72b2658d3b4a 100644 (file)
@@ -325,8 +325,7 @@ finished:
 
 static void unlink_object(const char *path)
 {
-       TALLOC_CTX *mem_ctx = talloc_new(NULL);
-       char *cmd;
+       char *rmcmd = NULL;
        int ret;
        struct stat st;
 
@@ -334,22 +333,27 @@ static void unlink_object(const char *path)
        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);
 }