Skip to content

Ownership engine: a NULL reset joined with a path where the resource is still live #276

Open

Description

@SizzleUnrlsd

Problem

Pattern 1 of the #104 comment of 2026-10-26 (libwebp EncodeImageInternal, sudo eventlog.c,
OpenSSH kex.c), in the shape that the engine-based DoubleRelease planned for #104 does not
cover: the pointer is released and reset to NULL, and the cleanup label is also reached by an
earlier path where the resource is still live.

// resource-model: models/resource-lifetime/generic.txt
#include <stdlib.h>

int null_reset_then_cleanup(int err, int err2)
{
    char* p = malloc(8);
    if (err)
        goto fail;          /* p live */
    free(p);
    p = NULL;
    if (err2)
        goto fail;          /* p NULL */
    return 0;
fail:
    free(p);                /* reported: potential double release */
    return 1;
}

At fail, the engine joins "p holds the resource, which is live" with "p holds NULL, the
resource is released", and keeps "p may hold the resource, which may be released". The
UseAfterRelease side has the same limit (known limit of #270:
if (c) { free(p); p = NULL; } if (p) *p = 1;).

A related case: when the variable's address is passed to a function anywhere in the function,
its stores are weak updates, so p = NULL after the release is not seen at all:

extern void unknown_out(void** pp);

void reset_with_address_taken(void)
{
    char* p = malloc(8);
    free(p);
    p = NULL;
    free(p);                 /* reported: potential double release */
    unknown_out((void**)&p);
}

Proposal

After a strong write to a storage location, a resource that leaves it, that no other storage
location names, and that is only Released becomes NotOwned on that path (parameter resources
excluded, so summaries and the cache do not change). The weak-update case needs its own rule.

This touches the state shared by UseAfterRelease, MissingRelease and ReferenceLost, so it
needs its own before/after measurement and a separate proof for aliases and for SSA values that
may still be used after the store.

Acceptance

  • null_reset_then_cleanup above: no report.
  • q = p; free(p); p = NULL; free(q);: still reported.
  • if (c) { free(p); p = NULL; } if (p) *p = 1;: no UseAfterRelease.

Part of #104.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FPbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions