[PATCH v10 1/5] PID namespace translation support
Ákos Uzonyi
uzonyi.akos at gmail.com
Sat Aug 22 19:37:55 UTC 2020
On Sat, 22 Aug 2020 at 19:52, Dmitry V. Levin <ldv at altlinux.org> wrote:
> On Wed, Aug 19, 2020 at 08:16:33PM +0200, Ákos Uzonyi wrote:
> [...]
> > +static uint64_t *
> > +trie_get_node(struct trie *t, uint64_t key, bool auto_create)
> > +{
> > + void **cur_node = &(t->data);
> > +
> > + if (t->key_size < 64 && key > (uint64_t) 1 << t->key_size)
> > + return NULL;
> > +
> > + for (uint8_t cur_depth = 0; cur_depth <= t->max_depth; cur_depth++) {
> > + uint8_t offs = trie_get_node_bit_offs(t, cur_depth);
> > + uint8_t sz = trie_get_node_size(t, cur_depth);
> > +
> > + if (!*cur_node) {
> > + if (!auto_create)
> > + return NULL;
> > +
> > + if (cur_depth == t->max_depth)
> > + *cur_node = trie_create_data_block(t);
> > + else
> > + *cur_node = calloc(1 << sz, 1);
> > +
> > + if (!*cur_node) {
> > + fprintf(stderr, "Out of memory");
> > + exit(1);
> > + }
>
> This should rather be error_msg_and_die("Out of memory");
>
> Or better use xcalloc instead of calloc here and in
> trie_create_data_block.
The problem is, trie.c is linked to the strace code and to the test
suite code too, so we can't use these functions (they do not exist in
the test environment). Originally xcalloc was used here, but when I
created the trie test, I replaced it with the code above.
fprintf(sterr); exit(1) seems to be fine, as this is used in
error_msg_and_die, and error_msg_and fail too.
More information about the Strace-devel
mailing list