diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2008-04-28 14:42:10 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2008-04-28 14:50:30 +0300 |
commit | 61f144522e830ac714679f2ed860d91ea387c3ee (patch) | |
tree | 4dc36d1c04c86104958b364c92531b51606acf8f /lib/fs.c | |
parent | 75a21293916e7b93b5059045a254ab8bb3ecc96f (diff) | |
download | rpm-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.c | 17 |
1 files changed, 11 insertions, 6 deletions
@@ -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 */ |