diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 1de983d9a05d503da17dbad640df6806a4f960f6..95f440d217e5a94a1022d413a968ca1322ac77fa 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -2549,6 +2549,8 @@ static void write_namespace_deps_files(void)
 		sprintf(fname, "%s.ns_deps", mod->name);
 		write_if_changed(&ns_deps_buf, fname);
 	}
+
+	free(ns_deps_buf.p);
 }
 
 struct ext_sym_list {