@@ -698,8 +698,7 @@ int32_t btf_elf__add_datasec_type(struct btf_elf *btfe, const char *section_name
static int btf_elf__write(const char *filename, struct btf *btf)
{
- GElf_Shdr shdr_mem, *shdr;
- GElf_Ehdr ehdr_mem, *ehdr;
+ GElf_Ehdr ehdr;
Elf_Data *btf_data = NULL;
Elf_Scn *scn = NULL;
Elf *elf = NULL;
@@ -727,13 +726,12 @@ static int btf_elf__write(const char *filename, struct btf *btf)
elf_flagelf(elf, ELF_C_SET, ELF_F_DIRTY);
- ehdr = gelf_getehdr(elf, &ehdr_mem);
- if (ehdr == NULL) {
+ if (!gelf_getehdr(elf, &ehdr)) {
elf_error("elf_getehdr failed");
goto out;
}
- switch (ehdr_mem.e_ident[EI_DATA]) {
+ switch (ehdr.e_ident[EI_DATA]) {
case ELFDATA2LSB:
btf__set_endianness(btf, BTF_LITTLE_ENDIAN);
break;
@@ -751,10 +749,10 @@ static int btf_elf__write(const char *filename, struct btf *btf)
elf_getshdrstrndx(elf, &strndx);
while ((scn = elf_nextscn(elf, scn)) != NULL) {
- shdr = gelf_getshdr(scn, &shdr_mem);
- if (shdr == NULL)
+ GElf_Shdr shdr;
+ if (!gelf_getshdr(scn, &shdr))
continue;
- char *secname = elf_strptr(elf, strndx, shdr->sh_name);
+ char *secname = elf_strptr(elf, strndx, shdr.sh_name);
if (strcmp(secname, ".BTF") == 0) {
btf_data = elf_getdata(scn, btf_data);
break;