Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
fix: fix memory leaks in ReceiveArray style array parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
halildurmus committed Nov 30, 2023
1 parent 0d0d579 commit 90681e9
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 20 deletions.
1 change: 1 addition & 0 deletions packages/windows_applicationmodel/lib/src/iappinfo4.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class IAppInfo4 extends IInspectable {
return value.value.toList(length: valueSize.value);
} finally {
free(valueSize);
free(value.value);
free(value);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ class IDisplayMonitor extends IInspectable {
return result.value.toList(length: resultSize.value);
} finally {
free(resultSize);
free(result.value);
free(result);
}
}
Expand Down
19 changes: 19 additions & 0 deletions packages/windows_foundation/lib/src/ipropertyvalue.dart
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ class IPropertyValue extends IInspectable {
return value.value.toList(length: valueSize.value);
} finally {
free(valueSize);
free(value.value);
free(value);
}
}
Expand All @@ -388,6 +389,7 @@ class IPropertyValue extends IInspectable {
return value.value.toList(length: valueSize.value);
} finally {
free(valueSize);
free(value.value);
free(value);
}
}
Expand All @@ -406,6 +408,7 @@ class IPropertyValue extends IInspectable {
return value.value.toList(length: valueSize.value);
} finally {
free(valueSize);
free(value.value);
free(value);
}
}
Expand All @@ -424,6 +427,7 @@ class IPropertyValue extends IInspectable {
return value.value.toList(length: valueSize.value);
} finally {
free(valueSize);
free(value.value);
free(value);
}
}
Expand All @@ -442,6 +446,7 @@ class IPropertyValue extends IInspectable {
return value.value.toList(length: valueSize.value);
} finally {
free(valueSize);
free(value.value);
free(value);
}
}
Expand All @@ -460,6 +465,7 @@ class IPropertyValue extends IInspectable {
return value.value.toList(length: valueSize.value);
} finally {
free(valueSize);
free(value.value);
free(value);
}
}
Expand All @@ -478,6 +484,7 @@ class IPropertyValue extends IInspectable {
return value.value.toList(length: valueSize.value);
} finally {
free(valueSize);
free(value.value);
free(value);
}
}
Expand All @@ -496,6 +503,7 @@ class IPropertyValue extends IInspectable {
return value.value.toList(length: valueSize.value);
} finally {
free(valueSize);
free(value.value);
free(value);
}
}
Expand All @@ -514,6 +522,7 @@ class IPropertyValue extends IInspectable {
return value.value.toList(length: valueSize.value);
} finally {
free(valueSize);
free(value.value);
free(value);
}
}
Expand All @@ -532,6 +541,7 @@ class IPropertyValue extends IInspectable {
return value.value.toStringList(length: valueSize.value);
} finally {
free(valueSize);
free(value.value);
free(value);
}
}
Expand All @@ -550,6 +560,7 @@ class IPropertyValue extends IInspectable {
return value.value.toList(length: valueSize.value);
} finally {
free(valueSize);
free(value.value);
free(value);
}
}
Expand All @@ -568,6 +579,7 @@ class IPropertyValue extends IInspectable {
return value.value.toList(length: valueSize.value);
} finally {
free(valueSize);
free(value.value);
free(value);
}
}
Expand All @@ -586,6 +598,7 @@ class IPropertyValue extends IInspectable {
return value.value.toObjectList(length: valueSize.value);
} finally {
free(valueSize);
free(value.value);
free(value);
}
}
Expand All @@ -604,6 +617,7 @@ class IPropertyValue extends IInspectable {
return value.value.toList(length: valueSize.value);
} finally {
free(valueSize);
free(value.value);
free(value);
}
}
Expand All @@ -622,6 +636,7 @@ class IPropertyValue extends IInspectable {
return value.value.toDateTimeList(length: valueSize.value);
} finally {
free(valueSize);
free(value.value);
free(value);
}
}
Expand All @@ -640,6 +655,7 @@ class IPropertyValue extends IInspectable {
return value.value.toDurationList(length: valueSize.value);
} finally {
free(valueSize);
free(value.value);
free(value);
}
}
Expand All @@ -658,6 +674,7 @@ class IPropertyValue extends IInspectable {
return value.value.toList(length: valueSize.value);
} finally {
free(valueSize);
free(value.value);
free(value);
}
}
Expand All @@ -676,6 +693,7 @@ class IPropertyValue extends IInspectable {
return value.value.toList(length: valueSize.value);
} finally {
free(valueSize);
free(value.value);
free(value);
}
}
Expand All @@ -694,6 +712,7 @@ class IPropertyValue extends IInspectable {
return value.value.toList(length: valueSize.value);
} finally {
free(valueSize);
free(value.value);
free(value);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ void main() {
return value.value;
} finally {
free(valueSize);
free(value.value);
free(value);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class IPixelDataProvider extends IInspectable {
return pixelData.value.toList(length: pixelDataSize.value);
} finally {
free(pixelDataSize);
free(pixelData.value);
free(pixelData);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class IDigitalWindowControl extends IInspectable {
.toEnumList(DigitalWindowMode.from, length: valueSize.value);
} finally {
free(valueSize);
free(value.value);
free(value);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class IAudioEncodingPropertiesWithFormatUserData extends IInspectable {
return value.value.toList(length: valueSize.value);
} finally {
free(valueSize);
free(value.value);
free(value);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ITimedMetadataEncodingProperties extends IInspectable {
return value.value.toList(length: valueSize.value);
} finally {
free(valueSize);
free(value.value);
free(value);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class IVideoEncodingProperties2 extends IInspectable {
return value.value.toList(length: valueSize.value);
} finally {
free(valueSize);
free(value.value);
free(value);
}
}
Expand Down
7 changes: 5 additions & 2 deletions packages/winrtgen/lib/src/projections/types/array.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ base class ReceiveArrayParameterProjection extends ArrayParameterProjection {
];

@override
List<String> get postambles =>
['free($sizeIdentifier);', 'free($identifier);'];
List<String> get postambles => [
'free($sizeIdentifier);',
'free($identifier.value);',
'free($identifier);'
];
}
26 changes: 19 additions & 7 deletions packages/winrtgen/test/projections/getter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -970,8 +970,8 @@ void main() {
projection.returnStatement,
equals(
'return value.value.toEnumList(DigitalWindowMode.from, length: valueSize.value);'));
expect(
projection.postambles, equals(['free(valueSize);', 'free(value);']));
expect(projection.postambles,
equals(['free(valueSize);', 'free(value.value);', 'free(value);']));
});

test('projects List<Guid>', () {
Expand Down Expand Up @@ -1007,8 +1007,14 @@ void main() {
projection.returnStatement,
equals(
'return contentKeyIds.value.toList(length: contentKeyIdsSize.value);'));
expect(projection.postambles,
equals(['free(contentKeyIdsSize);', 'free(contentKeyIds);']));
expect(
projection.postambles,
equals([
'free(contentKeyIdsSize);',
'free(contentKeyIds.value);',
'free(contentKeyIds);'
]),
);
});

test('projects List<int>', () {
Expand Down Expand Up @@ -1042,7 +1048,9 @@ void main() {
expect(projection.returnStatement,
equals('return value.value.toList(length: valueSize.value);'));
expect(
projection.postambles, equals(['free(valueSize);', 'free(value);']));
projection.postambles,
equals(['free(valueSize);', 'free(value.value);', 'free(value);']),
);
});

test('projects List<String>', () {
Expand Down Expand Up @@ -1076,7 +1084,9 @@ void main() {
expect(projection.returnStatement,
equals('return value.value.toList(length: valueSize.value);'));
expect(
projection.postambles, equals(['free(valueSize);', 'free(value);']));
projection.postambles,
equals(['free(valueSize);', 'free(value.value);', 'free(value);']),
);
});

test('projects List<Vector2>', () {
Expand Down Expand Up @@ -1110,7 +1120,9 @@ void main() {
expect(projection.returnStatement,
equals('return value.value.toList(length: valueSize.value);'));
expect(
projection.postambles, equals(['free(valueSize);', 'free(value);']));
projection.postambles,
equals(['free(valueSize);', 'free(value.value);', 'free(value);']),
);
});

test('projects Object', () {
Expand Down
30 changes: 21 additions & 9 deletions packages/winrtgen/test/projections/method_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1101,8 +1101,11 @@ void main() {
projection.returnStatement,
equals(
'return result.value.toEnumList(AnnotationType.from, length: resultSize.value);'));
expect(projection.postambles,
orderedEquals(['free(resultSize);', 'free(result);']));
expect(
projection.postambles,
orderedEquals(
['free(resultSize);', 'free(result.value);', 'free(result);']),
);
});

test('projects List<DisplayId>', () {
Expand Down Expand Up @@ -1134,8 +1137,11 @@ void main() {
expect(projection.nullCheck, isEmpty);
expect(projection.returnStatement,
equals('return result.value.toList(length: resultSize.value);'));
expect(projection.postambles,
orderedEquals(['free(resultSize);', 'free(result);']));
expect(
projection.postambles,
orderedEquals(
['free(resultSize);', 'free(result.value);', 'free(result);']),
);
});

test('projects List<int>', () {
Expand Down Expand Up @@ -1171,8 +1177,11 @@ void main() {
expect(projection.nullCheck, isEmpty);
expect(projection.returnStatement,
equals('return result.value.toList(length: resultSize.value);'));
expect(projection.postambles,
orderedEquals(['free(resultSize);', 'free(result);']));
expect(
projection.postambles,
orderedEquals(
['free(resultSize);', 'free(result.value);', 'free(result);']),
);
});

test('projects List<ITextRangeProvider?>', () {
Expand Down Expand Up @@ -1207,8 +1216,11 @@ void main() {
projection.returnStatement,
equals(
'return result.value.toList(ITextRangeProvider.fromPtr, length: resultSize.value);'));
expect(projection.postambles,
orderedEquals(['free(resultSize);', 'free(result);']));
expect(
projection.postambles,
orderedEquals(
['free(resultSize);', 'free(result.value);', 'free(result);']),
);
});

test('projects List<String> (Char16)', () {
Expand Down Expand Up @@ -1236,7 +1248,7 @@ void main() {
'int Function(VTablePointer lpVtbl, Pointer<Uint32> valueSize, Pointer<Pointer<Uint16>> value)'));
expect(projection.identifiers, equals('lpVtbl, valueSize, value'));
expect(projection.parametersPostamble,
equals(['free(valueSize);', 'free(value);']));
equals(['free(valueSize);', 'free(value.value);', 'free(value);']));
expect(projection.failedCheck, equals(failedCheck()));
expect(projection.nullCheck, isEmpty);
expect(projection.returnStatement,
Expand Down
4 changes: 2 additions & 2 deletions packages/winrtgen/test/projections/parameter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,8 @@ void main() {
'final valueSize = calloc<Uint32>();',
'final value = calloc<Pointer<IntPtr>>();'
]));
expect(
projection.postambles, equals(['free(valueSize);', 'free(value);']));
expect(projection.postambles,
equals(['free(valueSize);', 'free(value.value);', 'free(value);']));
expect(projection.nullCheck, isEmpty);
expect(projection.identifier, equals('value'));
expect(projection.localIdentifier, equals('value'));
Expand Down

0 comments on commit 90681e9

Please sign in to comment.