mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-09-21 19:15:44 +08:00
2010-06-21 Joel Sherrill <joel.sherrilL@OARcorp.com>
PR 1554/cpukit Coverity Id 17 * libi2c/libi2c.c, score/src/objectextendinformation.c: Fix memory leak on error.
This commit is contained in:
@@ -1,3 +1,10 @@
|
||||
2010-06-21 Joel Sherrill <joel.sherrilL@OARcorp.com>
|
||||
|
||||
PR 1554/cpukit
|
||||
Coverity Id 17
|
||||
* libi2c/libi2c.c, score/src/objectextendinformation.c: Fix memory leak
|
||||
on error.
|
||||
|
||||
2010-06-21 Joel Sherrill <joel.sherrilL@OARcorp.com>
|
||||
|
||||
PR 1559/misc
|
||||
|
||||
+10
-1
@@ -389,17 +389,23 @@ rtems_libi2c_register_bus (const char *name, rtems_libi2c_bus_t * bus)
|
||||
char tmp, *chpt;
|
||||
struct stat sbuf;
|
||||
|
||||
strcpy (nmcpy, name ? name : "/dev/i2c");
|
||||
if (nmcpy == NULL) {
|
||||
safe_printf ( DRVNM "No memory\n");
|
||||
return -RTEMS_NO_MEMORY;
|
||||
}
|
||||
|
||||
strcpy (nmcpy, name ? name : "/dev/i2c");
|
||||
|
||||
/* check */
|
||||
if ('/' != *nmcpy) {
|
||||
safe_printf ( DRVNM "Bad name: must be an absolute path starting with '/'\n");
|
||||
free( nmcpy );
|
||||
return -RTEMS_INVALID_NAME;
|
||||
}
|
||||
/* file must not exist */
|
||||
if (!stat (nmcpy, &sbuf)) {
|
||||
safe_printf ( DRVNM "Bad name: file exists already\n");
|
||||
free( nmcpy );
|
||||
return -RTEMS_INVALID_NAME;
|
||||
}
|
||||
|
||||
@@ -412,6 +418,7 @@ rtems_libi2c_register_bus (const char *name, rtems_libi2c_bus_t * bus)
|
||||
if (i) {
|
||||
safe_printf ( DRVNM "Get %s status failed: %s\n",
|
||||
nmcpy, strerror(errno));
|
||||
free( nmcpy );
|
||||
return -RTEMS_INVALID_NAME;
|
||||
}
|
||||
/* should be a directory since name terminates in '/' */
|
||||
@@ -419,11 +426,13 @@ rtems_libi2c_register_bus (const char *name, rtems_libi2c_bus_t * bus)
|
||||
|
||||
if (libmutex == RTEMS_ID_NONE) {
|
||||
safe_printf ( DRVNM "Library not initialized\n");
|
||||
free( nmcpy );
|
||||
return -RTEMS_NOT_DEFINED;
|
||||
}
|
||||
|
||||
if (bus == NULL || bus->size < sizeof (*bus)) {
|
||||
safe_printf ( DRVNM "No bus-ops or size too small -- misconfiguration?\n");
|
||||
free( nmcpy );
|
||||
return -RTEMS_NOT_CONFIGURED;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,11 +56,13 @@ void _Objects_Extend_information(
|
||||
uint32_t maximum;
|
||||
size_t block_size;
|
||||
void *new_object_block;
|
||||
bool do_extend;
|
||||
|
||||
/*
|
||||
* Search for a free block of indexes. The block variable ends up set
|
||||
* to block_count + 1 if the table needs to be extended.
|
||||
* Search for a free block of indexes. If we do NOT need to allocate or
|
||||
* extend the block table, then we will change do_extend.
|
||||
*/
|
||||
do_extend = true;
|
||||
minimum_index = _Objects_Get_index( information->minimum_id );
|
||||
index_base = minimum_index;
|
||||
block = 0;
|
||||
@@ -72,9 +74,10 @@ void _Objects_Extend_information(
|
||||
block_count = information->maximum / information->allocation_size;
|
||||
|
||||
for ( ; block < block_count; block++ ) {
|
||||
if ( information->object_blocks[ block ] == NULL )
|
||||
if ( information->object_blocks[ block ] == NULL ) {
|
||||
do_extend = false;
|
||||
break;
|
||||
else
|
||||
} else
|
||||
index_base += information->allocation_size;
|
||||
}
|
||||
}
|
||||
@@ -104,9 +107,9 @@ void _Objects_Extend_information(
|
||||
}
|
||||
|
||||
/*
|
||||
* If the index_base is the maximum we need to grow the tables.
|
||||
* Do we need to grow the tables?
|
||||
*/
|
||||
if (index_base >= information->maximum ) {
|
||||
if ( do_extend ) {
|
||||
ISR_Level level;
|
||||
void **object_blocks;
|
||||
uint32_t *inactive_per_block;
|
||||
|
||||
Reference in New Issue
Block a user