[PATCH] Fix static analyzers warnings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



- Reduce the scope of i, child_count
- Fd leak on failure
- Initialize st
---
 libkmod/libkmod-index.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libkmod/libkmod-index.c b/libkmod/libkmod-index.c
index 7f0c092..c376176 100644
--- a/libkmod/libkmod-index.c
+++ b/libkmod/libkmod-index.c
@@ -258,7 +258,6 @@ static struct index_node_f *index_read(FILE *in, uint32_t offset)
 {
 	struct index_node_f *node;
 	char *prefix;
-	int i, child_count = 0;
 
 	if ((offset & INDEX_NODE_MASK) == 0)
 		return NULL;
@@ -276,6 +275,7 @@ static struct index_node_f *index_read(FILE *in, uint32_t offset)
 	if (offset & INDEX_NODE_CHILDS) {
 		char first = read_char(in);
 		char last = read_char(in);
+		int i, child_count = 0;
 		child_count = last - first + 1;
 
 		node = NOFAIL(malloc(sizeof(struct index_node_f) +
@@ -343,6 +343,7 @@ struct index_file *index_file_open(const char *filename)
 
 	magic = read_long(file);
 	if (magic != INDEX_MAGIC)
+		fclose(file);
 		return NULL;
 
 	version = read_long(file);
@@ -724,7 +725,7 @@ struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename,
 		uint32_t root_offset;
 	} hdr;
 	void *p;
-
+	memset(&st, 0, sizeof(st));
 	DBG(ctx, "file=%s\n", filename);
 
 	idx = malloc(sizeof(*idx));
@@ -737,7 +738,6 @@ struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename,
 		ERR(ctx, "%m\n");
 		goto fail_open;
 	}
-
 	fstat(fd, &st);
 	flags = MAP_PRIVATE;
 	if (populate)
-- 
1.7.7

--
To unsubscribe from this list: send the line "unsubscribe linux-modules" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux