mirror of
https://github.com/AsahiLinux/u-boot
synced 2025-03-17 15:27:00 +00:00
spi: sandbox: Fix memory leak in sandbox_sf_bind_emul()
Move the strdup() call so that it is only done when we know we will bind the device. Reported-by: Coverity (CID: 131216) Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
8a682e03d7
commit
fb95283931
1 changed files with 4 additions and 3 deletions
|
@ -567,16 +567,17 @@ int sandbox_sf_bind_emul(struct sandbox_state *state, int busnum, int cs,
|
|||
strncpy(name, spec, sizeof(name) - 6);
|
||||
name[sizeof(name) - 6] = '\0';
|
||||
strcat(name, "-emul");
|
||||
str = strdup(name);
|
||||
if (!str)
|
||||
return -ENOMEM;
|
||||
drv = lists_driver_lookup_name("sandbox_sf_emul");
|
||||
if (!drv) {
|
||||
puts("Cannot find sandbox_sf_emul driver\n");
|
||||
return -ENOENT;
|
||||
}
|
||||
str = strdup(name);
|
||||
if (!str)
|
||||
return -ENOMEM;
|
||||
ret = device_bind(bus, drv, str, NULL, of_offset, &emul);
|
||||
if (ret) {
|
||||
free(str);
|
||||
printf("Cannot create emul device for spec '%s' (err=%d)\n",
|
||||
spec, ret);
|
||||
return ret;
|
||||
|
|
Loading…
Add table
Reference in a new issue