浏览代码

[commons] freemem on gethostname linux

Exilon 5 年之前
父节点
当前提交
79a59840b4
共有 1 个文件被更改,包括 13 次插入9 次删除
  1. 13 9
      Quick.Commons.pas

+ 13 - 9
Quick.Commons.pas

@@ -946,15 +946,19 @@ function GetComputerName : string;
       begin
         try
           phost := AllocMem(256);
-          if gethostname(phost,_SC_HOST_NAME_MAX) = 0 then
-          begin
-            {$IFDEF DEBUG}
-            Result := Copy(Trim(phost),1,Length(Trim(phost)));
-            {$ELSE}
-            Result := Copy(phost,1,Length(phost));
-            {$ENDIF}
-          end
-          else Result := 'N/A.';
+          try
+            if gethostname(phost,_SC_HOST_NAME_MAX) = 0 then
+            begin
+              {$IFDEF DEBUG}
+              Result := Copy(Trim(phost),1,Length(Trim(phost)));
+              {$ELSE}
+              Result := Copy(phost,1,Length(phost));
+              {$ENDIF}
+            end
+            else Result := 'N/A.';
+          finally
+            FreeMem(phost);
+          end;
         except
           Result := 'N/A';
         end;