Renamed some pointer variables, and explicitly free some memory pointers.
Renamed some variables and explicitly free memory pointers in the set_permissions method.