summaryrefslogtreecommitdiffstats
path: root/cpukit/libi2c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2010-06-21 16:27:37 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2010-06-21 16:27:37 +0000
commitad376300acbe6ef6505127e61ea3653e98d89558 (patch)
treebe1c5cca0468663ef4532d7870341b2980a34486 /cpukit/libi2c
parent2010-06-21 Joel Sherrill <joel.sherrilL@OARcorp.com> (diff)
downloadrtems-ad376300acbe6ef6505127e61ea3653e98d89558.tar.bz2
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.
Diffstat (limited to 'cpukit/libi2c')
-rw-r--r--cpukit/libi2c/libi2c.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/cpukit/libi2c/libi2c.c b/cpukit/libi2c/libi2c.c
index e43e667e3d..673488f6c8 100644
--- a/cpukit/libi2c/libi2c.c
+++ b/cpukit/libi2c/libi2c.c
@@ -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;
}