[#2212] CID25725 and CID25693:

Added null check to prevent possible null dereference
[#2212] CID25818:

Added null check to prevent null dereference
[#2212] CID25687:

added null check to avoid potential null dereference
[#2212] CID44262 and CID44273:

Added free to avoid potential leak