Fix static analysis issues reported by 3rd party tools (cherry picked from commit 24e82fe83d384e3a4cf17719e728760053516607)