Author: weiden
Date: Sat Oct 27 07:13:37 2007
New Revision: 29909
URL:
http://svn.reactos.org/svn/reactos?rev=29909&view=rev
Log:
Fix memory leaks/wrong heap usage by replacing calls to _tcsdup with cmd_dup
Modified:
trunk/reactos/base/shell/cmd/cmddbg.c
trunk/reactos/base/shell/cmd/cmddbg.h
trunk/reactos/base/shell/cmd/for.c
trunk/reactos/base/shell/cmd/where.c
Modified: trunk/reactos/base/shell/cmd/cmddbg.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/cmddbg.c?re…
==============================================================================
--- trunk/reactos/base/shell/cmd/cmddbg.c (original)
+++ trunk/reactos/base/shell/cmd/cmddbg.c Sat Oct 27 07:13:37 2007
@@ -146,6 +146,23 @@
free(ptr);
}
+TCHAR *
+cmd_dup_dbg(const TCHAR *str, const char *file, int line)
+{
+ TCHAR *ptr = NULL;
+
+ if (str != NULL)
+ {
+ ptr = (TCHAR *)cmd_alloc_dbg((_tcslen(str) + 1) * sizeof(TCHAR), file, line);
+ if (ptr != NULL)
+ {
+ _tcscpy(ptr, str);
+ }
+ }
+
+ return ptr;
+}
+
void
cmd_checkbuffer_dbg(void *ptr, const char *file, int line)
{
Modified: trunk/reactos/base/shell/cmd/cmddbg.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/cmddbg.h?re…
==============================================================================
--- trunk/reactos/base/shell/cmd/cmddbg.h (original)
+++ trunk/reactos/base/shell/cmd/cmddbg.h Sat Oct 27 07:13:37 2007
@@ -4,6 +4,7 @@
#define cmd_realloc(ptr,size) cmd_realloc_dbg(ptr, size, __FILE__, __LINE__)
#define cmd_free(ptr) cmd_free_dbg(ptr, __FILE__, __LINE__)
#define cmd_checkbuffer(ptr) cmd_checkbuffer_dbg(ptr, __FILE__, __LINE__)
+#define cmd_dup(str) cmd_dup_dbg(str, __FILE__, __LINE__)
void *
cmd_alloc_dbg(size_t size, const char *file, int line);
@@ -13,6 +14,9 @@
void
cmd_free_dbg(void *ptr, const char *file, int line);
+
+TCHAR *
+cmd_dup_dbg(const TCHAR *str, const char *file, int line);
void
cmd_checkbuffer_dbg(void *ptr, const char *file, int line);
@@ -25,6 +29,7 @@
#define cmd_alloc(size) malloc(size)
#define cmd_realloc(ptr,size) realloc(ptr, size)
#define cmd_free(ptr) free(ptr)
+#define cmd_dup(str) _tcsdup(str)
#define cmd_checkbuffer(ptr)
#endif
Modified: trunk/reactos/base/shell/cmd/for.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/for.c?rev=2…
==============================================================================
--- trunk/reactos/base/shell/cmd/for.c (original)
+++ trunk/reactos/base/shell/cmd/for.c Sat Oct 27 07:13:37 2007
@@ -135,7 +135,7 @@
bc->params = BatchParams (_T(""), param); /* Split out list */
bc->shiftlevel = 0;
bc->forvar = var;
- bc->forproto = _tcsdup (pp);
+ bc->forproto = cmd_dup (pp);
if (bc->prev)
bc->bEcho = bc->prev->bEcho;
else
Modified: trunk/reactos/base/shell/cmd/where.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/where.c?rev…
==============================================================================
--- trunk/reactos/base/shell/cmd/where.c (original)
+++ trunk/reactos/base/shell/cmd/where.c Sat Oct 27 07:13:37 2007
@@ -236,7 +236,7 @@
if (pExt != NULL)
{
LPTSTR pszBuffer2;
- pszBuffer2 = _tcsdup(pszBuffer);
+ pszBuffer2 = cmd_dup(pszBuffer);
if (pszBuffer2)
{
pCh = _tcstok(pszBuffer2, _T(";"));
@@ -245,12 +245,12 @@
if (0 == _tcsicmp(pCh, pExt))
{
cmd_free(pszBuffer);
- LocalFree(pszBuffer2);
+ cmd_free(pszBuffer2);
return SearchForExecutableSingle(pFileName, pFullName, NULL);
}
pCh = _tcstok(NULL, _T(";"));
}
- LocalFree(pszBuffer2);
+ cmd_free(pszBuffer2);
}
}