I’m trying to build iwlwifi module manually and for my needs.

https://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/iwlwifi-fixes.git/tree/net/wireless/

When I run Makefile as make, I get:

subcmd-util.h: In function ‘xrealloc’:
subcmd-util.h:58:31: error: pointer ‘ptr’ may be used after ‘realloc’ [-Werror=use-after-free]
   58 |                         ret = realloc(ptr, 1);
      |                               ^~~~~~~~~~~~~~~
subcmd-util.h:52:21: note: call to ‘realloc’ here
   52 |         void *ret = realloc(ptr, size);
      |                     ^~~~~~~~~~~~~~~~~~
subcmd-util.h:56:23: error: pointer ‘ptr’ may be used after ‘realloc’ [-Werror=use-after-free]
   56 |                 ret = realloc(ptr, size);
      |                       ^~~~~~~~~~~~~~~~~~
subcmd-util.h:52:21: note: call to ‘realloc’ here
   52 |         void *ret = realloc(ptr, size);
      |                     ^~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[4]: *** [/data/iwlwifi-fixes/tools/build/Makefile.build:97: /data/iwlwifi-fixes/tools/objtool/help.o] Error 1
make[3]: *** [Makefile:59: /data/iwlwifi-fixes/tools/objtool/libsubcmd-in.o] Error 2
make[2]: *** [Makefile:63: /data/iwlwifi-fixes/tools/objtool/libsubcmd.a] Error 2
make[1]: *** [Makefile:69: objtool] Error 2
make: *** [Makefile:1349: tools/objtool] Error 2

Why is it? How to fix it?

  • litchralee@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    0
    ·
    edit-2
    1 year ago

    No objections to your answer to the OP’s question, but as a curiosity, I’m trying to figure out what the original xrealloc() function is trying to do.

    So far as I can tell, it tries a normal realloc() with the requested size, but if that fails, tries again with size=1. But strangely, it that fails, tries using the requested size a second time. And if that still fails, tries once more with size=1.

    The POSIX man page isn’t giving me any hints as to why size=1 might be special, or if this is some sort of Linux-specific behavior or workaround. I wondered if you might have some insight why this function is the way it is.

    Note: I’m on mobile, so haven’t checked the Git Blame history yet.