]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Reduce indentation in handle_dfree_command with early returns
authorVolker Lendecke <vl@samba.org>
Tue, 13 Jan 2026 21:12:48 +0000 (22:12 +0100)
committerVolker Lendecke <vl@samba.org>
Tue, 20 Jan 2026 11:53:34 +0000 (11:53 +0000)
Review with git show -w

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
source3/smbd/dfree.c

index 1becfcc5dc3b97497cfd59224b313989afbcc0ba..338d50659f3459914b1723d29e03def0867d92a3 100644 (file)
@@ -59,64 +59,67 @@ static bool handle_dfree_command(connection_struct *conn,
 {
        const struct loadparm_substitution *lp_sub =
                loadparm_s3_global_substitution();
-       const char *dfree_command;
+       const char *dfree_command = NULL;
        char *path = fname->base_name;
+       const char *p = NULL;
+       char **lines = NULL;
+       char **argl = NULL;
+       char *line = NULL;
 
        dfree_command = lp_dfree_command(talloc_tos(), lp_sub, SNUM(conn));
-       if (dfree_command && *dfree_command) {
-               const char *p;
-               char **lines = NULL;
-               char **argl = NULL;
-
-               argl = str_list_make_empty(talloc_tos());
-               str_list_add_printf(&argl, "%s", dfree_command);
-               str_list_add_printf(&argl, "%s", path);
-               if (argl == NULL) {
-                       return false;
-               }
-
-               DBG_NOTICE("Running command '%s %s'\n",
-                       dfree_command,
-                       path);
-
-               lines = file_lines_ploadv(talloc_tos(), argl, NULL);
-
-               TALLOC_FREE(argl);
-
-               if (lines != NULL) {
-                       char *line = lines[0];
+       if (!dfree_command || !*dfree_command) {
+               return false;
+       }
 
-                       DBG_NOTICE("Read input from dfree, \"%s\"\n", line);
+       argl = str_list_make_empty(talloc_tos());
+       str_list_add_printf(&argl, "%s", dfree_command);
+       str_list_add_printf(&argl, "%s", path);
+       if (argl == NULL) {
+               return false;
+       }
 
-                       *dsize = STR_TO_SMB_BIG_UINT(line, &p);
-                       while (p && *p && isspace(*p))
-                               p++;
-                       if (p && *p)
-                               *dfree = STR_TO_SMB_BIG_UINT(p, &p);
-                       while (p && *p && isspace(*p))
-                               p++;
-                       if (p && *p)
-                               *bsize = STR_TO_SMB_BIG_UINT(p, NULL);
-                       else
-                               *bsize = 1024;
-                       TALLOC_FREE(lines);
+       DBG_NOTICE("Running command '%s %s'\n",
+               dfree_command,
+               path);
 
-                       DBG_NOTICE("Parsed output of dfree, dsize=%"PRIu64", "
-                                  "dfree=%"PRIu64", bsize=%"PRIu64"\n",
-                                  *dsize, *dfree, *bsize);
+       lines = file_lines_ploadv(talloc_tos(), argl, NULL);
 
-                       if (!*dsize)
-                               *dsize = 2048;
-                       if (!*dfree)
-                               *dfree = 1024;
+       TALLOC_FREE(argl);
 
-                       return true;
-               }
+       if (lines == NULL) {
                DBG_ERR("file_lines_load() failed for "
-                          "command '%s %s'. Error was : %s\n",
-                          dfree_command, path, strerror(errno));
+                       "command '%s %s'. Error was : %s\n",
+                       dfree_command, path, strerror(errno));
+               return false;
        }
-       return false;
+
+       line = lines[0];
+
+       DBG_NOTICE("Read input from dfree, \"%s\"\n", line);
+
+       *dsize = STR_TO_SMB_BIG_UINT(line, &p);
+       while (p && *p && isspace(*p))
+               p++;
+       if (p && *p)
+               *dfree = STR_TO_SMB_BIG_UINT(p, &p);
+       while (p && *p && isspace(*p))
+               p++;
+       if (p && *p)
+               *bsize = STR_TO_SMB_BIG_UINT(p, NULL);
+       else
+               *bsize = 1024;
+       TALLOC_FREE(lines);
+
+       DBG_NOTICE("Parsed output of dfree, dsize=%"PRIu64", "
+                  "dfree=%"PRIu64", bsize=%"PRIu64"\n",
+                  *dsize, *dfree, *bsize);
+
+       if (!*dsize)
+               *dsize = 2048;
+       if (!*dfree)
+               *dfree = 1024;
+
+       return true;
 }
 
 static uint64_t sys_disk_free(connection_struct *conn,