Hello,

Mikhail Karpov, le mar. 01 sept. 2026 21:47:11 +0700, a ecrit:
> diff --git a/eth-multiplexer/netfs_impl.c b/eth-multiplexer/netfs_impl.c
> index 83a2313..e4a03d4 100644
> --- a/eth-multiplexer/netfs_impl.c
> +++ b/eth-multiplexer/netfs_impl.c
> @@ -86,17 +86,27 @@ lookup (const char *name)
>    struct lnode *ln = (struct lnode *) lookup_dev_by_name (name);
>  
>    char *copied_name = malloc (strlen (name) + 1);
> +  if (!copied_name)
> +    return NULL;
> +
>    strcpy (copied_name, name);
> +  error_t err;
>    if (ln)
>      {
> -      new_node (ln, &ln->n);
> +      err = new_node (ln, &ln->n);
> +      if (err)
> +     return NULL;

Since new_node is returning the error code, you want to set errno = err
before returning NULL, so the caller can get the error from errno.

Yes, I know that new_node happens to have taken the error code from
errno, so errno already contains the error code, but the function
prototype doesn't say that, so the caller shouldn't assume that.

> diff --git a/ext2fs/dir.c b/ext2fs/dir.c
> index 55f2657..74a9ea2 100644
> --- a/ext2fs/dir.c
> +++ b/ext2fs/dir.c
> @@ -687,9 +693,16 @@ diskfs_direnter_hard (struct node *dp, const char *name, 
> struct node *np,
>        anything at all. */
>        if (diskfs_node_disknode (dp)->dirents)
>       {
> -       diskfs_node_disknode (dp)->dirents =
> +       int *new_dirents =
>           realloc (diskfs_node_disknode (dp)->dirents,
>                    (dp->dn_stat.st_size / DIRBLKSIZ * sizeof (int)));
> +       if (!new_dirents)
> +         {
> +           ext2_warning ("Failed to reallocate memory for new_dirents");
> +           return ENOENT;

It looks odd to return ENOENT from diskfs_direnter_hard.

And actually this code is just an optimization "It's cheap, start a
count" so if realloc fails you can just avoid starting a count.

> @@ -701,6 +714,12 @@ diskfs_direnter_hard (struct node *dp, const char *name, 
> struct node *np,
>       {
>         diskfs_node_disknode (dp)->dirents =
>           malloc (dp->dn_stat.st_size / DIRBLKSIZ * sizeof (int));
> +       if (!diskfs_node_disknode (dp)->dirents)
> +         {
> +           ext2_warning ("Failed to allocate memory for dirents");
> +           return ENOENT;
> +         }
> +

Same here.

>  
> diff --git a/libdiskfs/file-chg.c b/libdiskfs/file-chg.c
> index 18170c2..8883381 100644
> --- a/libdiskfs/file-chg.c
> +++ b/libdiskfs/file-chg.c
> @@ -43,7 +43,15 @@ diskfs_S_file_notice_changes (struct protid *cred, 
> mach_port_t notify)
>        pthread_mutex_unlock (&np->lock);
>        return err;
>      }
> +
>    req = malloc (sizeof (struct modreq));
> +  if (!req)
> +    {
> +      err = errno;
> +      pthread_mutex_unlock (&np->lock);

We should probably not call file_changed if the allocation failed in the
end. I.e. try to allocate first, and only on success call file_changed.

> diff --git a/libps/procstat.c b/libps/procstat.c
> index 4de4216..a34da63 100644
> --- a/libps/procstat.c
> +++ b/libps/procstat.c
> @@ -204,6 +204,12 @@ merge_procinfo (struct proc_stat *ps, ps_flags_t need, 
> ps_flags_t have)
>         ps->thread_waits = malloc (WAITS_MALLOC_SIZE);
>         ps->thread_waits_len = WAITS_MALLOC_SIZE;
>         ps->thread_waits_vm_alloced = 0;
> +       if (! ps->thread_waits)

Move it just next to the malloc call.

> diff --git a/nfsd/fsys.c b/nfsd/fsys.c
> index f746716..dc74e63 100644
> --- a/nfsd/fsys.c
> +++ b/nfsd/fsys.c
> @@ -96,8 +103,15 @@ init_filesystems (void)
>  
>        if (index >= fsystablesize)
>       {
> -       fsystable = (struct fsys_spec *)
> +       void *new_fsystable =
>           realloc (fsystable, index * 2 * sizeof (struct fsys_spec));
> +       if (!new_fsystable)
> +         {
> +           error (0, ENOMEM, "Cannot reallocate memory for fsystable");

Better use errno?

> diff --git a/startup/startup.c b/startup/startup.c
> index fe409f5..ab49d55 100644
> --- a/startup/startup.c
> +++ b/startup/startup.c
> @@ -1586,10 +1586,19 @@ S_startup_request_notification (mach_port_t server,
>       calls; this is important.  We need later notification requests
>       to get executed first.  */
>    nt = malloc (sizeof (struct ntfy_task));
> +  if (!nt)
> +    return ENOMEM;

Better use errno?

>    nt->notify_port = notify;
>    nt->next = ntfy_tasks;
> -  ntfy_tasks = nt;
>    nt->name = malloc (strlen (name) + 1);
> +  if (!nt->name)
> +    {
> +      free (nt);
> +      return ENOMEM;

Same.

Samuel

Reply via email to