Ignore:
Timestamp:
Jun 12, 2000, 3:03:00 PM (25 years ago)
Author:
phaller
Message:

Fix: (most stupid!!!) memory leaks in directory.cpp

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/directory.cpp

    r3642 r3693  
    1 /* $Id: directory.cpp,v 1.23 2000-06-01 11:28:44 sandervl Exp $ */
     1/* $Id: directory.cpp,v 1.24 2000-06-12 13:03:00 phaller Exp $ */
    22
    33/*
     
    1414 * Copyright 1995 Alexandre Julliard
    1515 *
    16  * TODO: System/window directories should be created by install program!
     16 * TODO:
     17 *  - System/window directories should be created by install program!
    1718 *
    1819 * Project Odin Software License can be found in LICENSE.TXT
     
    149150
    150151
    151 ODINFUNCTION1(BOOL,SetCurrentDirectoryA,LPCSTR,lpPathName)
    152 {
    153   if(HIWORD(lpPathName) == 0) {
    154         SetLastError(ERROR_INVALID_PARAMETER);
    155         return FALSE;
     152ODINFUNCTION1(BOOL,   SetCurrentDirectoryA,
     153              LPCSTR, lpstrDirectory)
     154{
     155  char szBuffer[260]; // MAXPATHLEN
     156 
     157  if(HIWORD(lpstrDirectory) == 0)
     158  {
     159    SetLastError(ERROR_INVALID_PARAMETER);
     160    return FALSE;
    156161  }
    157   int len = strlen(lpPathName);
    158   char *tmp=(char *)alloca(len + 1);
    159 
    160   strcpy(tmp, lpPathName);
    161   if(tmp[len - 1] == '/') {
    162         tmp[len-1] = '\\';
     162 
     163  // cut off trailing backslashes
     164  // not if a process wants to change to the root directory
     165  int len = lstrlenA(lpstrDirectory);
     166  if ( ( (lpstrDirectory[len - 1] == '\\') ||
     167         (lpstrDirectory[len - 1] == '/') ) &&
     168       (len != 1) )
     169  {
     170    lstrcpynA(szBuffer,
     171              lpstrDirectory,
     172              len - 1);
     173    szBuffer[len - 1] = 0;
     174    lpstrDirectory = szBuffer;
    163175  }
    164   //SvL: Don't remove trailing backslash if it wants to chdir to root dir
    165   if((tmp[len - 1] == '\\')  && len != 1)
    166     tmp[len -1] = 0;
    167 
    168   dprintf(("SetCurrentDirectoryA %s", tmp));
    169   return O32_SetCurrentDirectory((LPSTR)tmp);
     176
     177  dprintf(("SetCurrentDirectoryA %s", lpstrDirectory));
     178  return O32_SetCurrentDirectory((LPSTR)lpstrDirectory);
    170179}
    171180
     
    207216 *****************************************************************************/
    208217
    209 ODINFUNCTION2(BOOL,CreateDirectoryA,LPCSTR, arg1,PSECURITY_ATTRIBUTES,arg2)
    210 {
    211   int len = strlen(arg1);
    212   char *tmp=(char *)alloca(len + 1);
    213 
    214   strcpy(tmp, arg1);
    215   if(tmp[len -1] == '\\')
    216     tmp[len -1] = 0;
    217   dprintf(("CreateDirectoryA %s", tmp));
    218   return O32_CreateDirectory(tmp, arg2);
     218ODINFUNCTION2(BOOL,                CreateDirectoryA,
     219              LPCSTR,              lpstrDirectory,
     220              PSECURITY_ATTRIBUTES,arg2)
     221{
     222  char szBuffer[260]; // MAXPATHLEN
     223  int len = strlen(lpstrDirectory);
     224 
     225  // cut off trailing backslashes
     226  if (lpstrDirectory[len - 1] == '\\')
     227  {
     228    lstrcpynA(szBuffer,
     229              lpstrDirectory,
     230              len - 1);
     231    szBuffer[len - 1] = 0;
     232    lpstrDirectory = szBuffer;
     233  }
     234 
     235  dprintf(("CreateDirectoryA %s",
     236            lpstrDirectory));
     237 
     238  return(O32_CreateDirectory(szBuffer,
     239                             arg2));
    219240}
    220241
     
    289310
    290311  if(lpBuffer)
    291         asciibuffer = (char *)alloca(uSize+1);
    292 
    293   if(lpBuffer && asciibuffer == NULL) {
    294         DebugInt3();
     312    asciibuffer = (char *)alloca(uSize+1);
     313
     314  if(lpBuffer && asciibuffer == NULL)
     315  {
     316    DebugInt3();
    295317  }
    296318
    297319  rc = GetSystemDirectoryA(asciibuffer, uSize);
    298320  if(rc && asciibuffer)
    299         AsciiToUnicode(asciibuffer, lpBuffer);
    300 
     321    AsciiToUnicode(asciibuffer, lpBuffer);
     322 
     323  free(asciibuffer);
    301324  return(rc);
    302325}
     
    348371
    349372  if(lpBuffer)
    350         asciibuffer = (char *)alloca(uSize+1);
    351 
    352   if(lpBuffer && asciibuffer == NULL) {
    353         DebugInt3();
     373    asciibuffer = (char *)alloca(uSize+1);
     374
     375  if(lpBuffer && asciibuffer == NULL)
     376  {
     377    DebugInt3();
    354378  }
    355379
    356380  rc = GetWindowsDirectoryA(asciibuffer, uSize);
    357381  if(rc && asciibuffer)
    358         AsciiToUnicode(asciibuffer, lpBuffer);
    359 
     382    AsciiToUnicode(asciibuffer, lpBuffer);
     383 
     384  free(asciibuffer);
    360385  return(rc);
    361386}
     
    375400
    376401
    377 ODINFUNCTION1(BOOL,RemoveDirectoryA,LPCSTR,arg1)
    378 {
    379   int len = strlen(arg1);
    380   char *tmp=(char *)alloca(len + 1);
    381 
    382   strcpy(tmp, arg1);
    383   if(tmp[len -1] == '\\')
    384     tmp[len -1] = 0;
    385 
    386   dprintf(("RemoveDirectory %s", arg1));
    387 
    388   return O32_RemoveDirectory(tmp);
     402ODINFUNCTION1(BOOL,   RemoveDirectoryA,
     403              LPCSTR, lpstrDirectory)
     404{
     405  char szBuffer[260]; // MAXPATHLEN
     406  int len = strlen(lpstrDirectory);
     407 
     408  // cut off trailing backslashes
     409  if (lpstrDirectory[len - 1] == '\\')
     410  {
     411    lstrcpynA(szBuffer,
     412              lpstrDirectory,
     413              len - 1);
     414    szBuffer[len - 1] = 0;
     415    lpstrDirectory = szBuffer;
     416  }
     417 
     418  dprintf(("RemoveDirectory %s",
     419          lpstrDirectory));
     420
     421  return O32_RemoveDirectory(lpstrDirectory);
    389422}
    390423
Note: See TracChangeset for help on using the changeset viewer.