Skip to content

Commit 9cb643c

Browse files
committed
Fix memory leak
As reported by https://issues.oss-fuzz.com/516234241
1 parent 0d322f0 commit 9cb643c

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

ossfuzz/matio_hyperslab_fuzzer.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace
1616
{
1717

1818
constexpr int kMaxRank = 4;
19+
constexpr int kMaxVars = 16;
1920

2021
void
2122
TryHyperslab(mat_t *mat, matvar_t *matvar, FuzzedDataProvider &fdp)
@@ -96,14 +97,14 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
9697

9798
size_t n = 0;
9899
char *const *dir = Mat_GetDir(mat, &n);
99-
if ( n > 16 )
100-
n = 16;
100+
if ( n > kMaxVars )
101+
n = kMaxVars;
101102

102103
// Iterate, reading each variable's info and then exercising hyperslab
103104
// and linear-region reads against it.
104105
matvar_t *matvar;
105106
int loops = 0;
106-
while ( (matvar = Mat_VarReadNextInfo(mat)) != nullptr && loops < 16 ) {
107+
while ( (matvar = Mat_VarReadNextInfo(mat)) != nullptr && loops < kMaxVars ) {
107108
// First the metadata-driven hyperslab (no full data load).
108109
TryHyperslab(mat, matvar, fdp);
109110
// Then exercise the size / subscript helpers — these wrap arithmetic
@@ -146,6 +147,8 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
146147
Mat_VarFree(matvar);
147148
++loops;
148149
}
150+
if ( loops >= kMaxVars && matvar != nullptr )
151+
Mat_VarFree(matvar);
149152

150153
// Try named reads (Mat_VarRead by name) over the directory and call
151154
// hyperslab on those (with full data already loaded).

0 commit comments

Comments
 (0)