Commits

Serge Zaitsev  committed d5bd961

prevented some memory leaks

  • Participants
  • Parent commits 95d0520

Comments (0)

Files changed (2)

 
 void index_writer_destroy(struct index_writer *writer) {
 	// TODO 
+	size_t i;
+	for (i = 0; i < writer->files_count; i++) {
+		free(writer->files[i]);
+	}
+	free(writer->files);
+	free(writer->postings);
+	if (writer->set != NULL) {
+		sparse_set_destroy(writer->set);
+	}
 	free(writer);
 }
 
 	for (i = 0; i < entries_count; i++) {
 		fwrite(&entries[i], sizeof(entries[i]), 1, f);
 	}
+	free(entries);
+
 	/* update fileids_size */
 	fseek(f, offset, SEEK_SET);
 	fwrite(&fileids_size, sizeof(fileids_size), 1, f);
 struct sparse_set *sparse_set_create(unsigned int cap) {
 	struct sparse_set *set;
 	set = malloc(sizeof(*set) + cap * sizeof(set->dense[0]));
+	/* We can use unintialized memory here, but memset() is called
+	 * to prevent warnings from valgrind and other tools */
+	memset(set, 0, sizeof(*set) + cap * sizeof(set->dense[0]));
+	set->dense = NULL;
+	set->densesz = 0;
 	return set;
 }