Skip to content

Commit

Permalink
Cleaned up some mallocs.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Mar 13, 2005
1 parent 38a1c7f commit d992f43
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions physfs.c
Expand Up @@ -1230,7 +1230,6 @@ int __PHYSFS_verifySecurity(DirHandle *h, char *fname, int allowMissing)
int retval = 1;
char *start;
char *end;
char *str;

if (*fname == '\0') /* quick rejection. */
return(1);
Expand All @@ -1249,11 +1248,7 @@ int __PHYSFS_verifySecurity(DirHandle *h, char *fname, int allowMissing)
retval = 1;
} /* if */

/* !!! FIXME: Can we ditch this malloc()? */
start = str = malloc(strlen(fname) + 1);
BAIL_IF_MACRO(str == NULL, ERR_OUT_OF_MEMORY, 0);
strcpy(str, fname);

start = fname;
if (!allowSymLinks)
{
while (1)
Expand All @@ -1262,12 +1257,8 @@ int __PHYSFS_verifySecurity(DirHandle *h, char *fname, int allowMissing)
if (end != NULL)
*end = '\0';

if (h->funcs->isSymLink(h->opaque, str, &retval))
{
__PHYSFS_setError(ERR_SYMLINK_DISALLOWED);
free(str);
return(0); /* insecure. */
} /* if */
if (h->funcs->isSymLink(h->opaque, fname, &retval))
BAIL_MACRO(ERR_SYMLINK_DISALLOWED, 0); /* insecure. */

/* break out early if path element is missing. */
if (!retval)
Expand Down Expand Up @@ -1297,7 +1288,6 @@ int __PHYSFS_verifySecurity(DirHandle *h, char *fname, int allowMissing)
int PHYSFS_mkdir(const char *_dname)
{
DirHandle *h;
char *str;
char *start;
char *end;
int retval = 0;
Expand All @@ -1312,9 +1302,7 @@ int PHYSFS_mkdir(const char *_dname)
BAIL_IF_MACRO_MUTEX(writeDir == NULL, ERR_NO_WRITE_DIR, stateLock, 0);
h = writeDir;
BAIL_IF_MACRO_MUTEX(!__PHYSFS_verifySecurity(h,dname,1),NULL,stateLock,0);
start = str = dname;
BAIL_IF_MACRO_MUTEX(str == NULL, ERR_OUT_OF_MEMORY, stateLock, 0);
strcpy(str, dname);
start = dname;

while (1)
{
Expand All @@ -1324,10 +1312,10 @@ int PHYSFS_mkdir(const char *_dname)

/* only check for existance if all parent dirs existed, too... */
if (exists)
retval = h->funcs->isDirectory(h->opaque, str, &exists);
retval = h->funcs->isDirectory(h->opaque, dname, &exists);

if (!exists)
retval = h->funcs->mkdir(h->opaque, str);
retval = h->funcs->mkdir(h->opaque, dname);

if (!retval)
break;
Expand Down

0 comments on commit d992f43

Please sign in to comment.