From 443781d972c4b627e249a3f0762abfe1c0ff123a Mon Sep 17 00:00:00 2001 From: Erez_Zadok Date: Sun, 23 Sep 2007 13:36:43 -0400 Subject: [PATCH] queryfile: more efficient allocation Also avoids repeated calls to realloc(), which appear to tickle a possible glibc bug. --- progs/queryfile.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/progs/queryfile.c b/progs/queryfile.c index ac09a1a..b3ad218 100644 --- a/progs/queryfile.c +++ b/progs/queryfile.c @@ -325,7 +325,7 @@ int unionfs_query(const char *file_path, struct unionfs_branch **ufs_branches) } ret = 0; - *ufs_branches = malloc(sizeof(struct unionfs_branch)); + *ufs_branches = malloc(sizeof(struct unionfs_branch)*(len+1)); if (!(*ufs_branches)) { errno = ENOMEM; return -1; @@ -334,10 +334,7 @@ int unionfs_query(const char *file_path, struct unionfs_branch **ufs_branches) for (i = 0; i <= len; i++) { if (FD_ISSET(i, &branchlist)) { - *ufs_branches = realloc(*ufs_branches, - sizeof(struct unionfs_branch)*(ret+1)); - (*ufs_branches)[ret].path = malloc(strlen(branches[ret]+1)); - strcpy((*ufs_branches)[ret].path, branches[i]); + (*ufs_branches)[ret].path = strdup(branches[i]); (*ufs_branches)[ret].perms = branchperms[i]; ret++; } -- 2.43.0