浏览代码

LibC: Don't leave /etc/passwd open in getlogin()

Andreas Kling 5 年之前
父节点
当前提交
03c34cc73f
共有 1 个文件被更改,包括 2 次插入0 次删除
  1. 2 0
      Libraries/LibC/unistd.cpp

+ 2 - 0
Libraries/LibC/unistd.cpp

@@ -516,8 +516,10 @@ char* getlogin()
     static char __getlogin_buffer[256];
     if (auto* passwd = getpwuid(getuid())) {
         strncpy(__getlogin_buffer, passwd->pw_name, sizeof(__getlogin_buffer));
+        endpwent();
         return __getlogin_buffer;
     }
+    endpwent();
     return nullptr;
 }