Skip to content

Commit

Permalink
main: various fixes/cleanups in error handling
Browse files Browse the repository at this point in the history
Signed-off-by: Erik Sjölund <[email protected]>
  • Loading branch information
eriksjolund committed Feb 25, 2024
1 parent c2dd76c commit 0814774
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ read_mappings (const char *str)

tmp = malloc (sizeof (*tmp));
if (tmp == NULL)
return NULL;
error (EXIT_FAILURE, errno, "cannot allocate memory");
tmp->next = ret;
tmp->host = a;
tmp->to = b;
Expand Down Expand Up @@ -3102,6 +3102,10 @@ copyup (struct ovl_data *lo, struct ovl_node *node)
{
size_t current_size = PATH_MAX + 1;
cleanup_free char *p = malloc (current_size);
if (p == NULL) {
ret = -1;
goto exit;
}

while (1)
{
Expand All @@ -3115,8 +3119,10 @@ copyup (struct ovl_data *lo, struct ovl_node *node)

current_size = current_size * 2;
new = realloc (p, current_size);
if (new == NULL)
if (new == NULL) {
ret = -1;
goto exit;
}
p = new;
}
p[ret] = '\0';
Expand All @@ -3142,8 +3148,10 @@ copyup (struct ovl_data *lo, struct ovl_node *node)
}

buf = malloc (buf_size);
if (buf == NULL)
if (buf == NULL) {
ret = -1;
goto exit;
}

if (support_reflinks)
{
Expand Down Expand Up @@ -4755,12 +4763,10 @@ ovl_rename_direct (fuse_req_t req, fuse_ino_t parent, const char *name,

node->loaded = 0;

ret = 0;
fuse_reply_err (req, 0);
return;

error:
ret = -1;
fuse_reply_err (req, errno);
}

Expand Down Expand Up @@ -5536,6 +5542,10 @@ fuse_opt_proc (void *data, const char *arg, int key, struct fuse_args *outargs)
free (ovl_data->mountpoint);

ovl_data->mountpoint = strdup (arg);
if (ovl_data->mountpoint == NULL) {
fprintf (stderr, "cannot allocate memory\n");
return -1;
}
return 0;
}
/* Ignore unknown arguments. */
Expand Down Expand Up @@ -5589,6 +5599,8 @@ load_default_plugins ()
{
DIR *dp = NULL;
char *plugins = strdup ("");
if (plugins == NULL)
error (EXIT_FAILURE, errno, "cannot allocate memory");

dp = opendir (PKGLIBEXECDIR);
if (dp == NULL)
Expand Down Expand Up @@ -5839,8 +5851,10 @@ main (int argc, char *argv[])
cleanup_free char *path = NULL;

path = realpath (lo.workdir, NULL);
if (path == NULL)
if (path == NULL) {
ret = -1;
goto err_out1;
}
mkdir (path, 0700);
path = realloc (path, strlen (path) + strlen ("/work") + 1);
if (! path)
Expand Down Expand Up @@ -5870,11 +5884,13 @@ main (int argc, char *argv[])
if (se == NULL)
{
error (0, errno, "cannot create FUSE session");
ret = -1;
goto err_out1;
}
if (fuse_set_signal_handlers (se) != 0)
{
error (0, errno, "cannot set signal handler");
ret = -1;
goto err_out2;
}

Expand All @@ -5883,6 +5899,7 @@ main (int argc, char *argv[])
if (fuse_session_mount (se, lo.mountpoint) != 0)
{
error (0, errno, "cannot mount");
ret = -1;
goto err_out3;
}
fuse_daemonize (opts.foreground);
Expand Down

0 comments on commit 0814774

Please sign in to comment.