[rtems commit] leon,gr1553rt: Fixed memory leak
Daniel Hellstrom
danielh at rtems.org
Thu Mar 11 16:51:34 UTC 2021
Module: rtems
Branch: master
Commit: f798a75cd58da5a4250ed981ee2dee995597d6d5
Changeset: http://git.rtems.org/rtems/commit/?id=f798a75cd58da5a4250ed981ee2dee995597d6d5
Author: Arvid Bjorkengren <arvid at gaisler.com>
Date: Thu Oct 11 13:46:39 2018 +0200
leon,gr1553rt: Fixed memory leak
---
bsps/shared/grlib/1553/gr1553rt.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/bsps/shared/grlib/1553/gr1553rt.c b/bsps/shared/grlib/1553/gr1553rt.c
index 339e856..668a39e 100644
--- a/bsps/shared/grlib/1553/gr1553rt.c
+++ b/bsps/shared/grlib/1553/gr1553rt.c
@@ -147,7 +147,6 @@ static int gr1553rt_list_reg(struct gr1553rt_list *list)
return -1;
}
-#if 0 /* unused for now */
/* Unregister List from device */
static void gr1553rt_list_unreg(struct gr1553rt_list *list)
{
@@ -156,7 +155,6 @@ static void gr1553rt_list_unreg(struct gr1553rt_list *list)
priv->lists[list->listid] = NULL;
list->listid = -1;
}
-#endif
static int gr1553rt_bdid(void *rt, struct gr1553rt_sw_bd *bd)
{
@@ -240,7 +238,7 @@ int gr1553rt_list_init
{
struct gr1553rt_priv *priv = rt;
size_t size;
- int i;
+ int i, malloc_used;
struct gr1553rt_sw_bd *swbd;
unsigned short index;
struct gr1553rt_list *list;
@@ -251,6 +249,7 @@ int gr1553rt_list_init
* If the IN/OUT plist argument points to NULL a list
* dynamically allocated here.
*/
+ malloc_used = 0;
list = *plist;
if ( list == NULL ) {
/* Dynamically allocate LIST */
@@ -258,20 +257,27 @@ int gr1553rt_list_init
(cfg->bd_cnt * sizeof(list->bds[0]));
list = grlib_malloc(size);
if ( list == NULL )
- return -1;
+ return -1; /* Out of Memory */
*plist = list;
+ malloc_used = 1;
}
list->rt = rt;
list->subadr = -1;
list->listid = gr1553rt_list_reg(list);
- if ( list->listid == -1 )
+ if ( list->listid == -1 ) {
+ if (malloc_used)
+ free(list);
return -2; /* Too many lists */
+ }
list->cfg = cfg;
list->bd_cnt = cfg->bd_cnt;
/* Allocate all BDs needed by list */
if ( gr1553rt_bd_alloc(rt, &swbd, list->bd_cnt) ) {
+ gr1553rt_list_unreg(list);
+ if (malloc_used)
+ free(list);
return -3; /* Too few descriptors */
}
More information about the vc
mailing list