summaryrefslogtreecommitdiff
path: root/lib/fs.c
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2008-04-28 14:42:10 +0300
committerPanu Matilainen <pmatilai@redhat.com>2008-04-28 14:50:30 +0300
commit61f144522e830ac714679f2ed860d91ea387c3ee (patch)
tree4dc36d1c04c86104958b364c92531b51606acf8f /lib/fs.c
parent75a21293916e7b93b5059045a254ab8bb3ecc96f (diff)
downloadrpm-61f144522e830ac714679f2ed860d91ea387c3ee.tar.gz
rpm-61f144522e830ac714679f2ed860d91ea387c3ee.tar.bz2
rpm-61f144522e830ac714679f2ed860d91ea387c3ee.zip
Avoid alloca() in getFilesystemList()
Diffstat (limited to 'lib/fs.c')
-rw-r--r--lib/fs.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/fs.c b/lib/fs.c
index 80badb2f7..950efa500 100644
--- a/lib/fs.c
+++ b/lib/fs.c
@@ -55,19 +55,20 @@ int mntctl(int command, int size, char *buffer);
static int getFilesystemList(void)
{
int size;
- void * buf;
+ void * buf = NULL;
struct vmount * vm;
struct stat sb;
int rdonly = 0;
int num;
int fsnameLength;
int i;
+ int rc = 1; /* assume failure */
num = mntctl(MCTL_QUERY, sizeof(size), (char *) &size);
if (num < 0) {
rpmlog(RPMLOG_ERR, _("mntctl() failed to return size: %s\n"),
strerror(errno));
- return 1;
+ goto exit;
}
/*
@@ -77,12 +78,12 @@ static int getFilesystemList(void)
*/
size *= 2;
- buf = alloca(size);
+ buf = xmalloc(size);
num = mntctl(MCTL_QUERY, size, buf);
if ( num <= 0 ) {
rpmlog(RPMLOG_ERR, _("mntctl() failed to return mount points: %s\n"),
strerror(errno));
- return 1;
+ goto exit;
}
numFilesystems = num;
@@ -110,7 +111,7 @@ static int getFilesystemList(void)
strerror(errno));
rpmFreeFilesystems();
- return 1;
+ goto exit;
}
}
@@ -123,8 +124,12 @@ static int getFilesystemList(void)
filesystems[i].mntPoint = NULL;
fsnames[i] = NULL;
+ rc = 0;
- return 0;
+exit:
+ free(buf);
+
+ return rc;
}
#else /* HAVE_MNTCTL */