- /* Finally, add the permset to the access ACL. */
- int set_result = acl_set_entry(&acl, entry);
- if (set_result == ACL_ERROR) {
+ /* Finally, add the permset to the access ACL. It's actually
+ * important that we pass in the address of "acl" here, and not
+ * "acl" itself. Why? The call to acl_create_entry() within
+ * acl_set_entry() can allocate new memory for the entry.
+ * Sometimes that can be done in-place, in which case everything
+ * is cool and the new memory gets released when we call
+ * acl_free(acl).
+ *
+ * But occasionally, the whole ACL structure will have to be moved
+ * in order to allocate the extra space. When that happens,
+ * acl_create_entry() modifies the pointer it was passed (in this
+ * case, &acl) to point to the new location. We want to call
+ * acl_free() on the new location, and since acl_free() gets
+ * called right here, we need acl_create_entry() to update the
+ * value of "acl". To do that, it needs the address of "acl".
+ */
+ if (acl_set_entry(&acl, entry) == ACL_ERROR) {