context->proctitle.len = 0;
 }
 
+static inline void audit_free_module(struct audit_context *context)
+{
+       if (context->type == AUDIT_KERN_MODULE) {
+               kfree(context->module.name);
+               context->module.name = NULL;
+       }
+}
 static inline void audit_free_names(struct audit_context *context)
 {
        struct audit_names *n, *next;
 
 static inline void audit_free_context(struct audit_context *context)
 {
+       audit_free_module(context);
        audit_free_names(context);
        unroll_tree_refs(context, NULL, 0);
        free_tree_refs(context);
                audit_log_format(ab, "name=");
                if (context->module.name) {
                        audit_log_untrustedstring(ab, context->module.name);
-                       kfree(context->module.name);
                } else
                        audit_log_format(ab, "(null)");
 
        context->in_syscall = 0;
        context->prio = context->state == AUDIT_RECORD_CONTEXT ? ~0ULL : 0;
 
+       audit_free_module(context);
        audit_free_names(context);
        unroll_tree_refs(context, NULL, 0);
        audit_free_aux(context);