summaryrefslogtreecommitdiff
path: root/nuttx/sched
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-05-31 18:33:44 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-05-31 18:33:44 +0000
commitcce6409e1441451fd6ceef4f2a9d69dd04b5357d (patch)
treec39f3e932bf1844e367988117cddc22dac6f4a5b /nuttx/sched
parent7d9196d329877a5daad99c73aec57dc606076a56 (diff)
downloadpx4-nuttx-cce6409e1441451fd6ceef4f2a9d69dd04b5357d.tar.gz
px4-nuttx-cce6409e1441451fd6ceef4f2a9d69dd04b5357d.tar.bz2
px4-nuttx-cce6409e1441451fd6ceef4f2a9d69dd04b5357d.zip
Fix memory leak: Contained watchdog not being deleted with POSIX timer deleted
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@756 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/sched')
-rw-r--r--nuttx/sched/timer_delete.c12
-rw-r--r--nuttx/sched/wd_cancel.c55
-rw-r--r--nuttx/sched/wd_delete.c63
3 files changed, 79 insertions, 51 deletions
diff --git a/nuttx/sched/timer_delete.c b/nuttx/sched/timer_delete.c
index 066e158a6..386807575 100644
--- a/nuttx/sched/timer_delete.c
+++ b/nuttx/sched/timer_delete.c
@@ -72,7 +72,7 @@
*
********************************************************************************/
-static void timer_free(struct posix_timer_s *timer)
+static inline void timer_free(struct posix_timer_s *timer)
{
irqstate_t flags;
@@ -137,10 +137,12 @@ int timer_delete(timer_t timerid)
*get_errno_ptr() = EINVAL;
return ERROR;
}
-
- /* Disarm the timer */
-
- (void)wd_cancel(timer->pt_wdog);
+
+ /* Free the underlying watchdog instance (the timer will be canceled by the
+ * watchdog logic before it is actually deleted)
+ */
+
+ (void)wd_delete(timer->pt_wdog);
/* Release the timer structure */
diff --git a/nuttx/sched/wd_cancel.c b/nuttx/sched/wd_cancel.c
index 2872ce052..0a22edd5d 100644
--- a/nuttx/sched/wd_cancel.c
+++ b/nuttx/sched/wd_cancel.c
@@ -1,7 +1,7 @@
-/************************************************************
+/****************************************************************************
* wd_cancel.c
*
- * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@@ -14,7 +14,7 @@
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
- * 3. Neither the name Gregory Nutt nor the names of its contributors may be
+ * 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -31,11 +31,11 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Included Files
- ************************************************************/
+ ****************************************************************************/
#include <sys/types.h>
#include <assert.h>
@@ -44,31 +44,31 @@
#include "os_internal.h"
#include "wd_internal.h"
-/************************************************************
+/****************************************************************************
* Definitions
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Private Type Declarations
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Global Variables
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Private Variables
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Private Functions
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Public Functions
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Function: wd_cancel
*
* Description:
@@ -83,7 +83,7 @@
*
* Assumptions:
*
- ************************************************************/
+ ****************************************************************************/
STATUS wd_cancel (WDOG_ID wdid)
{
@@ -130,17 +130,24 @@ STATUS wd_cancel (WDOG_ID wdid)
* is being canceled, then it inherits the remaining ticks.
*/
- if (curr->next) curr->next->lag += curr->lag;
+ if (curr->next)
+ {
+ curr->next->lag += curr->lag;
+ }
/* Now, remove the watchdog from the timer queue */
if (prev)
- (void)sq_remafter((FAR sq_entry_t*)prev, &g_wdactivelist);
+ {
+ (void)sq_remafter((FAR sq_entry_t*)prev, &g_wdactivelist);
+ }
else
- (void)sq_remfirst(&g_wdactivelist);
+ {
+ (void)sq_remfirst(&g_wdactivelist);
+ }
wdid->next = NULL;
- /* If we made it this far, then we were successful */
+ /* Return success */
ret = OK;
}
diff --git a/nuttx/sched/wd_delete.c b/nuttx/sched/wd_delete.c
index 7e2a4328e..25f2db8ab 100644
--- a/nuttx/sched/wd_delete.c
+++ b/nuttx/sched/wd_delete.c
@@ -1,7 +1,7 @@
-/************************************************************
+/****************************************************************************
* wd_delete.c
*
- * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@@ -14,7 +14,7 @@
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
- * 3. Neither the name Gregory Nutt nor the names of its contributors may be
+ * 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -31,43 +31,47 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Included Files
- ************************************************************/
+ ****************************************************************************/
#include <sys/types.h>
+
#include <wdog.h>
#include <queue.h>
+#include <errno.h>
+
#include <nuttx/arch.h>
+
#include "wd_internal.h"
-/************************************************************
+/****************************************************************************
* Definitions
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Private Type Declarations
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Global Variables
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Private Variables
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Private Functions
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Public Functions
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Function: wd_delete
*
* Description:
@@ -86,16 +90,31 @@
* The caller has assured that the watchdog is no longer
* in use.
*
- ************************************************************/
+ ****************************************************************************/
STATUS wd_delete(WDOG_ID wdId)
{
irqstate_t saved_state;
- /* Check if the watchdog has been started. */
+ /* Verify that a valid watchdog was provided */
+
+ if (!wdId)
+ {
+ *get_errno_ptr() = EINVAL;
+ return ERROR;
+ }
+ /* The following steps are atomic... the watchdog must not be active when
+ * it is being deallocated.
+ */
saved_state = irqsave();
- if (wdId->active) wd_cancel(wdId);
+
+ /* Check if the watchdog has been started. */
+
+ if (wdId->active)
+ {
+ wd_cancel(wdId);
+ }
/* Put the watchdog back on the free list */