diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 13c6ca1d3..55996d1d5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -41,6 +41,10 @@ repos: name: check for null / false return mistmatch language: script entry: ./contrib/ci/check-null-false-returns.py + - id: check-finalizers + name: check for missing GObject parent finalize + language: script + entry: ./contrib/ci/check-finalizers.py - id: check-headers name: check for superfluous includes language: script diff --git a/contrib/ci/check-finalizers.py b/contrib/ci/check-finalizers.py new file mode 100755 index 000000000..3a0023d5d --- /dev/null +++ b/contrib/ci/check-finalizers.py @@ -0,0 +1,63 @@ +#!/usr/bin/python3 +# pylint: disable=invalid-name,missing-docstring,consider-using-f-string +# pylint: disable=too-few-public-methods +# +# Copyright (C) 2022 Richard Hughes +# +# SPDX-License-Identifier: LGPL-2.1+ + +import glob +import sys +from typing import List + + +class ReturnValidator: + def __init__(self): + self.warnings: List[str] = [] + + def parse(self, fn: str) -> None: + + with open(fn, "rb") as f: + infunc = False + has_parent_finalize = False + for line in f.read().decode().split("\n"): + + # found the function, but ignore the prototype + if line.find("_finalize(") != -1: + if line.endswith(";"): + continue + infunc = True + continue + + # got it + if line.find("->finalize(") != -1: + has_parent_finalize = True + continue + + # finalize is done + if infunc and line.startswith("}"): + if not has_parent_finalize: + self.warnings.append( + "{} did not have parent ->finalize()".format(fn) + ) + break + + +def test_files(): + + # test all C source files + validator = ReturnValidator() + for fn in glob.glob("**/*.c", recursive=True): + if fn.startswith("dist/") or fn.startswith("subprojects/"): + continue + validator.parse(fn) + for warning in validator.warnings: + print(warning) + + return 1 if validator.warnings else 0 + + +if __name__ == "__main__": + + # all done! + sys.exit(test_files()) diff --git a/plugins/corsair/fu-corsair-device.c b/plugins/corsair/fu-corsair-device.c index 6bbfcabb0..c5bb31d5f 100644 --- a/plugins/corsair/fu-corsair-device.c +++ b/plugins/corsair/fu-corsair-device.c @@ -508,6 +508,8 @@ fu_corsair_device_finalize(GObject *object) g_free(self->subdevice_id); g_object_unref(self->bp); + + G_OBJECT_CLASS(fu_corsair_device_parent_class)->finalize(object); } static void