Skip to content

Commit 120c4a1

Browse files
xiaoxiang781216pkarashchenko
authored andcommitted
modlib: Move modlib_allocbuffer to modlib_sectname and modlib_symname
it's better to allocate the buffer just before really use it. Signed-off-by: Xiang Xiao <[email protected]>
1 parent 879dab0 commit 120c4a1

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

libs/libc/modlib/modlib_bind.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -811,17 +811,6 @@ int modlib_bind(FAR struct module_s *modp,
811811
return ret;
812812
}
813813

814-
/* Allocate an I/O buffer. This buffer is used by mod_symname() to
815-
* accumulate the variable length symbol name.
816-
*/
817-
818-
ret = modlib_allocbuffer(loadinfo);
819-
if (ret < 0)
820-
{
821-
berr("ERROR: modlib_allocbuffer failed: %d\n", ret);
822-
return -ENOMEM;
823-
}
824-
825814
/* Process relocations in every allocated section */
826815

827816
for (i = 1; i < loadinfo->ehdr.e_shnum; i++)

libs/libc/modlib/modlib_sections.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ static inline int modlib_sectname(FAR struct mod_loadinfo_s *loadinfo,
7373
return -EINVAL;
7474
}
7575

76+
/* Allocate an I/O buffer. This buffer is used by modlib_sectname() to
77+
* accumulate the variable length symbol name.
78+
*/
79+
80+
ret = modlib_allocbuffer(loadinfo);
81+
if (ret < 0)
82+
{
83+
berr("ERROR: modlib_allocbuffer failed: %d\n", ret);
84+
return -ENOMEM;
85+
}
86+
7687
/* Get the section name string table section header */
7788

7889
shstr = &loadinfo->shdr[shstrndx];

libs/libc/modlib/modlib_symbols.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ static int modlib_symname(FAR struct mod_loadinfo_s *loadinfo,
109109
return -ESRCH;
110110
}
111111

112+
/* Allocate an I/O buffer. This buffer is used by mod_symname() to
113+
* accumulate the variable length symbol name.
114+
*/
115+
116+
ret = modlib_allocbuffer(loadinfo);
117+
if (ret < 0)
118+
{
119+
berr("ERROR: modlib_allocbuffer failed: %d\n", ret);
120+
return -ENOMEM;
121+
}
122+
112123
offset = sh_offset + sym->st_name;
113124

114125
/* Loop until we get the entire symbol name into memory */

0 commit comments

Comments
 (0)