``++free++`` or ``++delete++`` a block of memory and even though the memory has been released, your pointer still hold the address of the memory. Unless the pointer is immediately and explicitly reset to a null value (0 or ``++NULL++``), access to that freed memory could inadvertently be made, causing potentially serious problems at runtime.


== Noncompliant Code Example

----
void do_something() {
  char *cp;

  cp = malloc(10*sizeof(char));
  // ...

  free(cp);  // Noncompliant; not set to NULL
  // ...
}

void do_something_else() {
  int *int_array;

  int_array = new int_array[5];
  // ...

  delete int_array;  // Noncompliant
  // ...
}
----


== Compliant Solution

----
void do_something() {
  char *cp;

  cp = malloc(10*sizeof(char));
  // ...

  free(cp);
  cp = NULL;
  // ...
}

void do_something_else() {
  int *int_array;

  int_array = new int_array[5];
  // ...

  delete int_array;
  int_array = NULL;
  // ...
}
----


== Exceptions

Automatic pointers are ignored when the only statements between the release of their memory and the end of the function are other ``++free++``/``++delete++`` statements.


----
void do_other_thing(char *cp1) {
  char *cp;

  cp = malloc(10*sizeof(char));
  cp1 = malloc(10*sizeof(char));
  // ...

  free(cp);  // Ignored
  free(cp1); // Noncompliant; not an automatic variable
}
----


== See

* https://wiki.sei.cmu.edu/confluence/x/FNYxBQ[CERT, MEM01-C.] - Store a new value in pointers immediately after free()

