cdrom.c, network.c, tools.c: Fix memory leaks
This commit is contained in:
parent
cca0e7faa9
commit
68ad717ec3
21
cdrom.c
21
cdrom.c
@ -68,11 +68,22 @@ static int mount_that_cd_device(char * dev_name)
|
||||
/* test_that_cd() returns 0 on success */
|
||||
static int test_that_cd(int no_digest)
|
||||
{
|
||||
if (IS_VERIFICATION && !no_digest)
|
||||
return verify_ramdisk_digest(get_ramdisk_path(NULL),
|
||||
char *ramdisk_path = get_ramdisk_path(NULL);
|
||||
int rc;
|
||||
|
||||
if (IS_VERIFICATION && !no_digest) {
|
||||
rc = verify_ramdisk_digest(ramdisk_path,
|
||||
get_param_valued("hash")) == RETURN_ERROR;
|
||||
log_message("test file on cd: %s\n", get_ramdisk_path(NULL));
|
||||
return access(get_ramdisk_path(NULL), R_OK);
|
||||
goto done;
|
||||
}
|
||||
|
||||
log_message("test file on cd: %s\n", ramdisk_path);
|
||||
|
||||
rc = access(ramdisk_path, R_OK);
|
||||
|
||||
done:
|
||||
free(ramdisk_path);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@ -114,6 +125,8 @@ static enum return_type do_with_device(char * dev_name, char * dev_model)
|
||||
my_mount(LIVE_DEVICE, STAGE2_LOCATION, (IS_LIVE) ? LIVEFS : STAGE2FS, 0);
|
||||
}
|
||||
|
||||
free(ramdisk_path);
|
||||
|
||||
method_name = strdup("cdrom");
|
||||
add_to_env("METHOD", method_name);
|
||||
add_to_env("PREFIX", "/");
|
||||
|
12
network.c
12
network.c
@ -748,6 +748,8 @@ enum return_type nfs_prepare(void)
|
||||
my_mount(LIVE_DEVICE, STAGE2_LOCATION, (IS_LIVE) ? LIVEFS : STAGE2FS, 0);
|
||||
}
|
||||
|
||||
free(ramdisk_path);
|
||||
|
||||
method_name = strdup("nfs");
|
||||
add_to_env("METHOD", method_name);
|
||||
add_to_env("HOST", answers[0]);
|
||||
@ -782,6 +784,7 @@ enum return_type ftp_prepare(void)
|
||||
char location_full[500];
|
||||
int ftp_serv_response;
|
||||
int fd, size;
|
||||
char *tmp;
|
||||
|
||||
snprintf(location_full, sizeof(location_full),
|
||||
"Please enter the name or IP address of the FTP server, "
|
||||
@ -808,7 +811,9 @@ enum return_type ftp_prepare(void)
|
||||
continue;
|
||||
}
|
||||
strcpy(location_full, answers[1]);
|
||||
strcat(location_full, get_ramdisk_realname());
|
||||
tmp = get_ramdisk_realname();
|
||||
strcat(location_full, tmp);
|
||||
free(tmp);
|
||||
|
||||
log_message("FTP: trying to retrieve %s", location_full);
|
||||
|
||||
@ -874,6 +879,7 @@ enum return_type http_prepare(void)
|
||||
|
||||
do {
|
||||
char location_full[500];
|
||||
char *tmp;
|
||||
int fd, size;
|
||||
|
||||
snprintf(location_full, sizeof(location_full),
|
||||
@ -886,7 +892,9 @@ enum return_type http_prepare(void)
|
||||
}
|
||||
|
||||
strcpy(location_full, answers[1]);
|
||||
strcat(location_full, get_ramdisk_realname());
|
||||
tmp = get_ramdisk_realname();
|
||||
strcat(location_full, tmp);
|
||||
free(tmp);
|
||||
|
||||
log_message("HTTP: trying to retrieve %s", location_full);
|
||||
|
||||
|
13
tools.c
13
tools.c
@ -408,6 +408,7 @@ char * get_ramdisk_path(const char *mount_path)
|
||||
/* FIXME */
|
||||
strcpy(img_name, mount_path ? mount_path : IMAGE_LOCATION);
|
||||
strcat(img_name, st2_path);
|
||||
free(st2_path);
|
||||
return strdup(img_name);
|
||||
}
|
||||
|
||||
@ -472,6 +473,7 @@ enum return_type load_ramdisk(char *ramdisk_path, unsigned long size)
|
||||
{
|
||||
int st2_fd;
|
||||
char *img_name;
|
||||
enum return_type rc = RETURN_ERROR;
|
||||
|
||||
img_name = ramdisk_path ?: get_ramdisk_path(NULL);
|
||||
|
||||
@ -482,16 +484,21 @@ enum return_type load_ramdisk(char *ramdisk_path, unsigned long size)
|
||||
if (st2_fd == -1) {
|
||||
log_message("open ramdisk file (%s) failed", img_name);
|
||||
stg1_error_message("Could not open compressed ramdisk file (%s).", img_name);
|
||||
return RETURN_ERROR;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (size == 0) {
|
||||
size = get_ramdisk_size(img_name);
|
||||
if (size == 0)
|
||||
return RETURN_ERROR;
|
||||
goto done;
|
||||
}
|
||||
rc = load_ramdisk_fd(st2_fd, size);
|
||||
|
||||
return load_ramdisk_fd(st2_fd, size);
|
||||
done:
|
||||
if (img_name != ramdisk_path)
|
||||
free(img_name);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* pixel's */
|
||||
|
Loading…
Reference in New Issue
Block a user