fix-casts.sh

Thu, 22 Mar 2018 22:38:30 +0000

author
David Woodhouse <dwmw2@infradead.org>
date
Thu, 22 Mar 2018 22:38:30 +0000
branch
trac17292
changeset 38940
f6a28025f715
parent 24975
7abe1341dc45
permissions
-rwxr-xr-x

Fix memory leaks in pidgin_notify_searchresults_new_rows()

We were failing to free the new results structure, and also by using
g_value_set_string() we were allocating a redundant copy of each
string which we were failing to clean up.

Fixes #17292

#!/bin/sh

if [ $# -eq 0 ]; then
	echo "Usage: `basename "$0"` PurpleFoo..."
	echo
	echo "This script searches the *current working directory* and replaces casts"
	echo "with GObject-style type checking and casting macros."
	echo 'For example, "(PurpleBuddy *)b" becomes "PURPLE_BUDDY(b)".'
	exit 0
fi

for struct in $* ; do
	cast=`echo $struct | sed "s|[A-Z]|_\0|g" | tr "a-z" "A-Z" | sed "s|^_||"`
	for file in `grep -rl "([[:space:]]*$struct[[:space:]]*\*[[:space:]]*)" . --include=*.c --exclude=purple-client-bindings.c` ; do
		sed -i "s|([[:space:]]*$struct[[:space:]]*\*[[:space:]]*)[[:space:]]*(|$cast(|g" $file
		sed -i "s|([[:space:]]*$struct[[:space:]]*\*[[:space:]]*)[[:space:]]*\([^(][^,);]*\)|$cast(\1)|g" $file
	done
done

mercurial