Fix errors found by cppcheck
[disk.c:206]: (error) Resource leak: f [modules.c:62]: (error) Memory leak: buffer [modules.c:68]: (error) Common realloc mistake: 'buffer' nulled but not freed upon failure [stage1.c:101]: (error) va_list 'args' was opened but not closed by va_end(). [url.c:297]: (error) Resource leak: dataSocket
This commit is contained in:
parent
e88e097f15
commit
c96ab958b2
2
disk.c
2
disk.c
@ -202,6 +202,8 @@ static enum return_type try_with_device(char *dev_name)
|
||||
|
||||
if (!(f = fopen("/proc/partitions", "rb")) || !fgets(buf, sizeof(buf), f) || !fgets(buf, sizeof(buf), f)) {
|
||||
log_perror(dev_name);
|
||||
if (f)
|
||||
fclose(f);
|
||||
stg1_error_message("Could not read partitions information.");
|
||||
return RETURN_ERROR;
|
||||
}
|
||||
|
16
modules.c
16
modules.c
@ -55,17 +55,27 @@ static void *grab_file(const char *filename, unsigned long *size)
|
||||
{
|
||||
unsigned int max = 16384;
|
||||
int ret, fd;
|
||||
void *buffer = malloc(max);
|
||||
void *buffer;
|
||||
|
||||
fd = open(filename, O_RDONLY, 0);
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
|
||||
buffer = malloc(max);
|
||||
if (!buffer)
|
||||
return NULL;
|
||||
|
||||
*size = 0;
|
||||
while ((ret = read(fd, buffer + *size, max - *size)) > 0) {
|
||||
*size += ret;
|
||||
if (*size == max)
|
||||
buffer = realloc(buffer, max *= 2);
|
||||
if (*size == max) {
|
||||
void *nbuffer = realloc(buffer, max *= 2);
|
||||
if (!nbuffer) {
|
||||
free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
buffer = nbuffer;
|
||||
}
|
||||
}
|
||||
if (ret < 0) {
|
||||
free(buffer);
|
||||
|
1
stage1.c
1
stage1.c
@ -98,6 +98,7 @@ void stg1_info_message(char *msg, ...)
|
||||
va_start(args, msg);
|
||||
if (IS_AUTOMATIC) {
|
||||
vlog_message(msg, args);
|
||||
va_end(args);
|
||||
return;
|
||||
}
|
||||
vinfo_message(msg, args);
|
||||
|
Loading…
x
Reference in New Issue
Block a user