Fix bug about memory leak and arrange code
1. add checking when malloc fail.
2. add using local variable to return value.
3. add initial variable.
5. fix code convention.
4. fix other small comments by Habib.
Change-Id: I59219b87021b36256674d09e76419ebb03c38264
Signed-off-by: jyong2.kim <jyong2.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/814
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Habib Virji <habib.virji@samsung.com>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>