Wed, 30 May 2018 10:44:51 +0200
fixes realloc problem and memory leak in isfileindir() in sync.c
dav/sync.c | file | annotate | diff | comparison | revisions |
--- a/dav/sync.c Wed May 30 10:27:44 2018 +0200 +++ b/dav/sync.c Wed May 30 10:44:51 2018 +0200 @@ -2333,12 +2333,18 @@ static int isfileindir(SyncDirectory *dir, const char *path, SyncFile *f) { char *fullpath; if(path[0] != '/') { - size_t wdlen = 1024; - char *wd = malloc(1024); + size_t wdlen = 256; + char *wd = malloc(wdlen); while(!getcwd(wd, wdlen)) { if(errno == ERANGE) { wdlen *= 2; - wd = realloc(wd, wdlen); + char *newbuf = realloc(wd, wdlen); + if (newbuf) { + wd = newbuf; + } else { + free(wd); + return 0; + } } else { free(wd); return 0; @@ -2346,6 +2352,7 @@ } fullpath = util_concat_path(wd, path); + free(wd); } else { fullpath = strdup(path); }