device: Fix the reusing gerror without re-initialization
authorTedd Ho-Jeong An <tedd.an@intel.com>
Fri, 11 Feb 2022 02:00:53 +0000 (18:00 -0800)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:53 +0000 (14:55 +0530)
commit2da1784388b934d28efb2a3357863560624f9b86
tree4a8185df8c90d5c51deab37caadfb1154ba47cbd
parentb6606c3d6453e76cd6dbff902c021cf486df2273
device: Fix the reusing gerror without re-initialization

When the GError variable is freeed with g_error_free(), it is not set to
NULL and reusing the same variable again can cause the seg_fault because
it is still pointing the old memory address which is freed.

This patch relaces the g_error_free() to g_clear_error() which frees the
variable and set it to NULL if the variable is used in the function
again.

Fixes: 6a154cd08000b ("device: Fix unchecked return value")
Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
src/device.c