[Ttssh2-commit] [7345] メモリリーク修正、FileTruncateをmingwでコンパイルできるよう修正

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2018年 12月 23日 (日) 02:30:17 JST


Revision: 7345
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/7345
Author:   zmatsuo
Date:     2018-12-23 02:30:17 +0900 (Sun, 23 Dec 2018)
Log Message:
-----------
メモリリーク修正、FileTruncateをmingwでコンパイルできるよう修正

Modified Paths:
--------------
    branches/cmake/teraterm/common/codeconv.cpp
    branches/cmake/teraterm/ttpmacro/ttl.cpp
    branches/cmake/tests/test_file.ttl

-------------- next part --------------
Modified: branches/cmake/teraterm/common/codeconv.cpp
===================================================================
--- branches/cmake/teraterm/common/codeconv.cpp	2018-12-22 17:30:03 UTC (rev 7344)
+++ branches/cmake/teraterm/common/codeconv.cpp	2018-12-22 17:30:17 UTC (rev 7345)
@@ -384,6 +384,7 @@
 {
 	const wchar_t *strW = _MultiByteToWideChar(strU8, 0, CP_UTF8, NULL);
 	tc _tc = strW;
+	free((void *)strW);
 	return _tc;
 }
 

Modified: branches/cmake/teraterm/ttpmacro/ttl.cpp
===================================================================
--- branches/cmake/teraterm/ttpmacro/ttl.cpp	2018-12-22 17:30:03 UTC (rev 7344)
+++ branches/cmake/teraterm/ttpmacro/ttl.cpp	2018-12-22 17:30:17 UTC (rev 7345)
@@ -2091,8 +2091,8 @@
 	TStrVal FName;
 	int result = -1;
 	int TruncByte;
-	int fh = -1;
 	int ret;
+	FILE *fp;
 
 	Err = 0;
 	GetStrVal(FName,&Err);
@@ -2114,26 +2114,22 @@
 	}
 
 	// ファイルを指定したサイズで切り詰める。
-	ret = _tsopen_s( &fh, tc::fromUtf8(FName), _O_RDWR | _O_CREAT, _SH_DENYNO, _S_IREAD | _S_IWRITE );
-	if (ret != 0) {
+	fp = _tfopen(tc::fromUtf8(FName), _T("rb+"));
+	if (fp == NULL) {
 		Err = ErrCantOpen;
 		goto end;
 	}
-	ret = _chsize_s(fh, TruncByte);
+	ret = _chsize_s(_fileno(fp), TruncByte);
 	if (ret != 0) {
 		Err = ErrInvalidCtl;
 		goto end;
 	}
+	fclose(fp);
 
 	result = 0;
 	Err = 0;
-
 end:
 	SetResult(result);
-
-	if (fh != -1)
-		_close(fh);
-
 	return Err;
 }
 

Modified: branches/cmake/tests/test_file.ttl
===================================================================
--- branches/cmake/tests/test_file.ttl	2018-12-22 17:30:03 UTC (rev 7344)
+++ branches/cmake/tests/test_file.ttl	2018-12-22 17:30:17 UTC (rev 7345)
@@ -8,7 +8,7 @@
 ;call test_filestat
 ;call test_find
 ;call test_folder
-call test_password
+;call test_password
 messagebox "finish all tests" "test_file.ttl"
 end
 
@@ -73,6 +73,9 @@
 if result <> 0 messagebox "filecopy error" "test_file.ttl"
 filetruncate fname_1 1024
 if result <> 0 messagebox "filetruncate error" "test_file.ttl"
+filestat fname_1 size
+if result = -1 messagebox "filestat error" "test_file.ttl"
+if size <> 1024 messagebox "file size?" "test_file.ttl"
 messagebox "checkfiles 3" "test_file.ttl"
 filedelete fname_1
 if result <> 0 messagebox "filedelete error" "test_file.ttl"
@@ -81,6 +84,7 @@
 filedelete fname_3
 if result <> 0 messagebox "filedelete error" "test_file.ttl"
 messagebox "checkfiles 4" "test_file.ttl"
+return
 
 ;;;
 ;;; filesearch


Ttssh2-commit メーリングリストの案内
Back to archive index