// mem.in1
// simple functions that manage memory

int * owner malloc();
void free(int * owner p);
void do_stuff(int *p, int *q);

void ok()
{
  int * owner p;
  p = malloc();
  if (p) {
    *p = 5;
    free(p);
  }
}

void leaks()
{
  int * owner p;
  p = malloc();
  p = malloc();           // LEAK of p
}                         // LEAK of p

void bad_derefs()
{
  int * owner p;
  *p = 6;                 // BAD DEREF
  p = 0;
  *p = 7;                 // BAD DEREF
}

void more_complicated()
{
  int * owner p, * owner q;
  p = malloc();
  if (p) {
    q = malloc();
    if (q) {
      do_stuff(p, q);
      free(q);
    }
    free(p);
  }
}

/*
void bad()
{
  int * q;
  q = malloc();
  free(q);
}
*/
