From 56543e131182d5edf5caceb665ea427f31a6df71 Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Thu, 5 Sep 2019 15:58:00 +0200 Subject: [PATCH] nbis: Add spatch file to use GLib memory management functions Add an spatch/coccinelle file to replace all free/malloc/realloc calls with g_free/g_malloc/g_realloc. It also removes all the error code paths that we do not need to check anymore. --- libfprint/nbis/glib-memory.cocci | 29 +++++++++++++++++++++++++++++ libfprint/nbis/update-from-nbis.sh | 2 ++ 2 files changed, 31 insertions(+) create mode 100644 libfprint/nbis/glib-memory.cocci diff --git a/libfprint/nbis/glib-memory.cocci b/libfprint/nbis/glib-memory.cocci new file mode 100644 index 0000000..c2ac323 --- /dev/null +++ b/libfprint/nbis/glib-memory.cocci @@ -0,0 +1,29 @@ +@ free @ +expression ptr; +@@ +- free(ptr); ++ g_free(ptr); +@ malloc @ +type ptr_type; +expression ptr; +expression size; +@@ +- ptr = (ptr_type) malloc(size); ++ ptr = (ptr_type) g_malloc(size); + ... +( +- if (ptr == (ptr_type) NULL) { ... } +| +) +@ realloc @ +type ptr_type; +expression ptr; +expression size; +@@ +- ptr = (ptr_type) realloc(ptr, size); ++ ptr = (ptr_type) g_realloc(ptr, size); + ... +( +- if (ptr == (ptr_type) NULL) { ... } +| +) diff --git a/libfprint/nbis/update-from-nbis.sh b/libfprint/nbis/update-from-nbis.sh index bd3a59b..4e243a2 100755 --- a/libfprint/nbis/update-from-nbis.sh +++ b/libfprint/nbis/update-from-nbis.sh @@ -179,3 +179,5 @@ sed -i 's/[ \t]*$//' `find -name "*.[ch]"` # Remove usebsd.h sed -i '/usebsd.h/d' `find -name "*.[ch]"` +# Use GLib memory management +spatch --sp-file glib-memory.cocci --dir . --in-place \ No newline at end of file