kernel/timer: move a location of marking not in use
This commit fixs SVACE issue as shown below.
WID:5109936 Pointer '&timer->pt_flags' is dereferenced
at timer_release.c:120 after the referenced memory was
deallocated at sched_free.c:135 by passing as 1st parameter
to function 'sched_ufree' at timer_release.c:115.
@@ -114,10 +114,6 @@ static inline void timer_free(struct posix_timer_s *timer)
irqrestore(flags);
sched_kfree(timer);
}
-
- /* Mark this timer is not in use */
-
- timer->pt_flags &= ~PT_FLAGS_INUSE;
}
/********************************************************************************
@@ -167,6 +163,12 @@ int timer_release(FAR struct posix_timer_s *timer)
(void)wd_delete(timer->pt_wdog);
+ /* Mark this timer is not in use before releasing the timer.
+ * This prevents returning some value when timer API is called after release
+ */
+
+ timer->pt_flags &= ~PT_FLAGS_INUSE;
+
/* Release the timer structure */
timer_free(timer);
