loader: file_addmetadata() should check for memory allocation

malloc() can return NULL.

MFC after:	1w
This commit is contained in:
Toomas Soome 2019-04-07 12:10:19 +00:00
parent 1d28f39d20
commit d28c594669

View File

@ -677,10 +677,12 @@ file_addmetadata(struct preloaded_file *fp, int type, size_t size, void *p)
struct file_metadata *md;
md = malloc(sizeof(struct file_metadata) - sizeof(md->md_data) + size);
md->md_size = size;
md->md_type = type;
bcopy(p, md->md_data, size);
md->md_next = fp->f_metadata;
if (md != NULL) {
md->md_size = size;
md->md_type = type;
bcopy(p, md->md_data, size);
md->md_next = fp->f_metadata;
}
fp->f_metadata = md;
}