On 24.07.2014 08:41, Peter Krempa wrote:
On 07/23/14 21:06, Daniel P. Berrange wrote:
> On Wed, Jul 23, 2014 at 05:37:17PM +0200, Michal Privoznik wrote:
>> +int
>> +virFileFindHugeTLBFS(virHugeTLBFSPtr *ret_fs,
>> + size_t *ret_nfs)
>> +{
>> + int ret = -1;
>> + FILE *f = NULL;
>> + struct mntent mb;
>> + char mntbuf[1024];
>> + virHugeTLBFSPtr fs = NULL;
>> + size_t nfs = 0;
>> + unsigned long long default_hugepagesz;
>> +
>> + if (virFileGetDefaultHugepageSize(&default_hugepagesz) < 0)
>> + goto cleanup;
>> +
>> + if (!(f = setmntent(PROC_MOUNTS, "r"))) {
>> + virReportSystemError(errno,
>> + _("Unable to open %s"),
>> + PROC_MOUNTS);
>> + goto cleanup;
>> + }
>> +
>> + while (getmntent_r(f, &mb, mntbuf, sizeof(mntbuf))) {
>> + virHugeTLBFSPtr tmp;
>> +
>> + if (STRNEQ(mb.mnt_type, "hugetlbfs"))
>> + continue;
>> +
>> + if (VIR_REALLOC_N(fs, nfs + 1) < 0)
>> + goto cleanup;
>> +
>> + tmp = &fs[nfs];
>> + nfs++;
>
> Stilll think we should be using VIR_EXPAND_N here to ensure
> new space is fully zerod.
Or perhaps use VIR_APPEND_ELEMENT?
Okay, I'm squashing this in:
diff --git a/src/util/virfile.c b/src/util/virfile.c
index f18a0f5..8ce20f5 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -3008,11 +3008,10 @@ virFileFindHugeTLBFS(virHugeTLBFSPtr *ret_fs,
if (STRNEQ(mb.mnt_type, "hugetlbfs"))
continue;
- if (VIR_REALLOC_N(fs, nfs + 1) < 0)
+ if (VIR_EXPAND_N(fs, nfs, 1) < 0)
goto cleanup;
- tmp = &fs[nfs];
- nfs++;
+ tmp = &fs[nfs - 1];
if (VIR_STRDUP(tmp->mnt_dir, mb.mnt_dir) < 0)
goto cleanup;
Michal