cake icon indicating copy to clipboard operation
cake copied to clipboard

missing lifetime checks

Open thradams opened this issue 1 year ago • 1 comments

#include <ownership.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

struct X {
    char * owner s;
};
void destroy(struct X * obj_owner p) {free(p->s);}

void f1(){
    struct X x = {0};
    struct X* p = &x;
    x.s = strdup("a");
    destroy(&x);
    printf("%s", p->s);
}

void f2(){
    struct X* p = 0;

    {
        struct X x = {0};    
        p = &x;
        x.s = strdup("a");
        destroy(&x);
    }
    
    printf("%s", p->s);
}

int main(){
    
}

thradams avatar Jan 04 '24 11:01 thradams

unit test created

thradams avatar Jul 13 '24 00:07 thradams