Commit eb9dc676 authored by deuce's avatar deuce
Browse files

Fix last commit... only free() target if we malloc()ed it.

parent 3b11acf3
...@@ -870,11 +870,13 @@ ulong DLLCALL getdisksize(const char* path, ulong unit) ...@@ -870,11 +870,13 @@ ulong DLLCALL getdisksize(const char* path, ulong unit)
char * DLLCALL _fullpath(char *target, const char *path, size_t size) { char * DLLCALL _fullpath(char *target, const char *path, size_t size) {
char *out; char *out;
char *p; char *p;
BOOL target_alloced=FALSE;
if(target==NULL) { if(target==NULL) {
if((target=malloc(MAX_PATH+1))==NULL) { if((target=malloc(MAX_PATH+1))==NULL) {
return(NULL); return(NULL);
} }
target_alloced=TRUE;
} }
out=target; out=target;
*out=0; *out=0;
...@@ -883,7 +885,8 @@ char * DLLCALL _fullpath(char *target, const char *path, size_t size) { ...@@ -883,7 +885,8 @@ char * DLLCALL _fullpath(char *target, const char *path, size_t size) {
if(*path == '~') { if(*path == '~') {
p=getenv("HOME"); p=getenv("HOME");
if(p==NULL || strlen(p)+strlen(path)>=size) { if(p==NULL || strlen(p)+strlen(path)>=size) {
free(target); if(target_alloced)
free(target);
return(NULL); return(NULL);
} }
strcpy(target,p); strcpy(target,p);
...@@ -893,7 +896,8 @@ char * DLLCALL _fullpath(char *target, const char *path, size_t size) { ...@@ -893,7 +896,8 @@ char * DLLCALL _fullpath(char *target, const char *path, size_t size) {
else { else {
p=getcwd(NULL,size); p=getcwd(NULL,size);
if(p==NULL || strlen(p)+strlen(path)>=size) { if(p==NULL || strlen(p)+strlen(path)>=size) {
free(target); if(target_alloced)
free(target);
return(NULL); return(NULL);
} }
strcpy(target,p); strcpy(target,p);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment