1# Copyright (C) 2016 and later: Unicode, Inc. and others. 2# License & terms of use: http://www.unicode.org/copyright.html 3# *********************************************************************** 4# * COPYRIGHT: 5# * Copyright (c) 2004-2006, International Business Machines Corporation 6# * and others. All Rights Reserved. 7# *********************************************************************** 8# 9# This perl script checks for correct memory function usage in ICU library code. 10# It works with Linux builds of ICU using clang or gcc. 11# 12# To run it, 13# 1. Build ICU 14# 2. cd icu/source 15# 3. perl tools/memcheck/ICUMemCheck.pl 16# 17# All object files containing direct references to C or C++ runtime library memory 18# functions will be listed in the output. 19# 20# For ICU 58, the expected output is 21# common/uniset.o U operator delete(void*) 22# common/unifilt.o U operator delete(void*) 23# common/cmemory.o U malloc 24# common/cmemory.o U free 25# i18n/strrepl.o U operator delete(void*) 26# 27# cmemory.c Expected failures from uprv_malloc, uprv_free implementation. 28# uniset.cpp Fails because of SymbolTable::~SymbolTable() 29# unifilt.cpp Fails because of UnicodeMatcher::~UnicodeMatcher() 30# strrepl.cpp Fails because of UnicodeReplacer::~UnicodeReplacer() 31# 32# To verify that no additional problems exist in the .cpp files, #ifdef out the 33# offending destructors, rebuild icu, and re-run the tool. The problems should 34# be gone. 35# 36# The problem destructors all are for mix-in style interface classes. 37# These classes can not derive from UObject or UMemory because of multiple-inheritance 38# problems, so they don't get the ICU memory functions. The delete code 39# in the destructors will never be called because stand-alone instances of 40# the classes cannot exist. 41# 42$fileNames = `find common i18n io -name "*.o" -print`; 43foreach $f (split('\n', $fileNames)) { 44 $symbols = `nm -u -C $f`; 45 if ($symbols =~ /U +operator delete\(void\*\)/) { 46 print "$f $&\n"; 47 } 48 if ($symbols =~ /U +operator delete\[\]\(void\*\)/) { 49 print "$f $&\n"; 50 } 51 if ($symbols =~ /U +operator new\(unsigned int\)/) { 52 print "$f $&\n"; 53 } 54 if ($symbols =~ /U +operator new\[\]\(unsigned int\)/) { 55 print "$f $&\n"; 56 } 57 if ($symbols =~ /U +malloc.*/) { 58 print "$f $&\n"; 59 } 60 if ($symbols =~ /(?m:U +free$)/) { 61 print "$f $&\n"; 62 } 63 64} 65