mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-06-03 15:59:52 +08:00
rtemsbsd/rtems: Don't leak memory on error
This commit is contained in:
parent
62e0ca8283
commit
26ddd7dfca
@ -94,8 +94,6 @@ bsd_mountroot(const char *fstype)
|
||||
if (vfsp != NULL) {
|
||||
mp = vfs_mount_alloc(NULLVP, vfsp, "/", cred);
|
||||
|
||||
crfree(cred);
|
||||
|
||||
error = VFS_MOUNT(mp);
|
||||
if (error != 0)
|
||||
panic("Cannot mount root file system: %d", error);
|
||||
@ -114,6 +112,8 @@ bsd_mountroot(const char *fstype)
|
||||
|
||||
set_rootvnode(mp);
|
||||
}
|
||||
|
||||
crfree(cred);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -260,12 +260,14 @@ rc_conf_create(rtems_bsd_rc_conf** rc_conf,
|
||||
*/
|
||||
length = strnlen(text, RTEMS_BSD_RC_CONF_MAX_SIZE);
|
||||
if (length == RTEMS_BSD_RC_CONF_MAX_SIZE) {
|
||||
free(_rc_conf);
|
||||
errno = E2BIG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
copy = strdup(text);
|
||||
if (copy == NULL) {
|
||||
free(_rc_conf);
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
@ -286,6 +288,7 @@ rc_conf_create(rtems_bsd_rc_conf** rc_conf,
|
||||
lines = malloc(sizeof(char*) * line_count);
|
||||
if (lines == NULL) {
|
||||
free(copy);
|
||||
free(_rc_conf);
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
@ -335,6 +338,13 @@ rc_conf_create(rtems_bsd_rc_conf** rc_conf,
|
||||
if (timeout >= 0)
|
||||
_rc_conf->waiter = rtems_task_self();
|
||||
|
||||
if (_rc_conf->name == NULL) {
|
||||
free((void*) _rc_conf->lines);
|
||||
free((void*) _rc_conf->data);
|
||||
free(_rc_conf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create the lock.
|
||||
*/
|
||||
@ -343,6 +353,7 @@ rc_conf_create(rtems_bsd_rc_conf** rc_conf,
|
||||
free((void*) _rc_conf->name);
|
||||
free((void*) _rc_conf->lines);
|
||||
free((void*) _rc_conf->data);
|
||||
free(_rc_conf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -796,6 +807,7 @@ rtems_bsd_run_rc_conf_script(const char* name,
|
||||
if (sc != RTEMS_SUCCESSFUL) {
|
||||
fprintf(stderr, "error: %s: get priority: %s\n",
|
||||
name, rtems_status_text(sc));
|
||||
rc_conf_destroy(rc_conf);
|
||||
errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
@ -808,6 +820,7 @@ rtems_bsd_run_rc_conf_script(const char* name,
|
||||
&worker);
|
||||
if (sc != RTEMS_SUCCESSFUL) {
|
||||
fprintf (stderr, "error: worker create: %s", rtems_status_text(sc));
|
||||
rc_conf_destroy(rc_conf);
|
||||
errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
@ -817,6 +830,7 @@ rtems_bsd_run_rc_conf_script(const char* name,
|
||||
(rtems_task_argument) rc_conf);
|
||||
if (sc != RTEMS_SUCCESSFUL) {
|
||||
fprintf (stderr, "error: worker start: %s", rtems_status_text(sc));
|
||||
rc_conf_destroy(rc_conf);
|
||||
errno = EIO;
|
||||
return - 1;
|
||||
}
|
||||
|
@ -85,8 +85,10 @@ int rtems_get_route(const struct sockaddr_in* sin, struct sockaddr** rti_info)
|
||||
}
|
||||
|
||||
s = socket(AF_ROUTE, SOCK_RAW, AF_UNSPEC);
|
||||
if (s < 0)
|
||||
if (s < 0) {
|
||||
free(buf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
rtm = (struct rt_msghdr *) buf;
|
||||
rtm->rtm_msglen = sizeof(struct rt_msghdr) + sizeof(struct sockaddr_in);
|
||||
|
Loading…
x
Reference in New Issue
Block a user