jcs
/subtext
/amendments
/233
folder: Fix some memory leaks, pass malloc notes to bile
jcs made amendment 233 over 2 years ago
--- folder.c Sun Jul 31 21:23:06 2022
+++ folder.c Wed Aug 3 14:15:05 2022
@@ -327,7 +327,7 @@ folder_list_files(struct session *s, struct folder *fo
file_ids[off + n], &data);
bile_unmarshall_object(folder->bile, folder_file_object_fields,
nfolder_file_object_fields, data, size, &file, sizeof(file),
- false);
+ false, "folder_list_files");
xfree(&data);
strftime(time, sizeof(time), "%Y-%m-%d", localtime(&file.time));
@@ -675,7 +675,8 @@ folder_file_view(struct session *s, struct folder *fol
panic("failed fetching message %ld: %d", id,
bile_error(folder->bile));
bile_unmarshall_object(folder->bile, folder_file_object_fields,
- nfolder_file_object_fields, data, size, &file, sizeof(file), true);
+ nfolder_file_object_fields, data, size, &file, sizeof(file), true,
+ "folder_file_view");
xfree(&data);
dopts = xmalloc(sizeof(opts), "folder_file_view opts");
@@ -687,7 +688,7 @@ folder_file_view(struct session *s, struct folder *fol
dopts[3].key[0] = '\0';
}
- uploader = user_find_username(file.uploader_user_id);
+ uploader = user_username(file.uploader_user_id);
strftime(time, sizeof(time), "%Y-%m-%d %H:%M:%S",
localtime(&file.time));
@@ -837,6 +838,11 @@ folder_file_view(struct session *s, struct folder *fol
}
}
+ if (file.notes != NULL)
+ xfree(&file.notes);
+
+ xfree(&dopts);
+
return ret;
}
@@ -868,7 +874,7 @@ folder_find_file_ids(struct folder *folder, size_t *nf
bile_read_alloc(folder->bile, FOLDER_FILE_RTYPE, o->id, &data);
bile_unmarshall_object(folder->bile, folder_file_object_fields,
nfolder_file_object_fields, data, o->size, &file, sizeof(file),
- false);
+ false, "folder_find_file_ids");
xfree(&data);
xfree(&o);
@@ -893,6 +899,8 @@ folder_find_file_ids(struct folder *folder, size_t *nf
for (i = 0; i < *nfile_ids; i++)
(*file_ids)[i] = name_map[i].id;
+ xfree(&name_map);
+
done:
return *nfile_ids;
}
@@ -901,6 +909,7 @@ bool
folder_file_save(struct folder *folder, struct folder_file *file,
char *temp_path)
{
+ char note[MALLOC_NOTE_SIZE];
char *new_name = NULL;
short ret;
char *data;
@@ -911,8 +920,9 @@ folder_file_save(struct folder *folder, struct folder_
file->id = bile_next_id(folder->bile, FOLDER_FILE_RTYPE);
file->time = Time;
+ snprintf(note, sizeof(note), "folder_file_save %ld", file->id);
ret = bile_marshall_object(folder->bile, folder_file_object_fields,
- nfolder_file_object_fields, file, &data, &size);
+ nfolder_file_object_fields, file, &data, &size, note);
if (ret != 0 || size == 0) {
warn("failed to marshall new file object");
file->id = 0;
@@ -1036,7 +1046,7 @@ folder_file_valid_filename(struct session *session,
bile_read_alloc(folder->bile, FOLDER_FILE_RTYPE, o->id, &data);
bile_unmarshall_object(folder->bile, folder_file_object_fields,
nfolder_file_object_fields, data, o->size, &tfile, sizeof(tfile),
- false);
+ false, "folder_file_valid_filename");
xfree(&data);
xfree(&o);