Skip to content

Do not free a static string#238

Merged
bbonev merged 3 commits intoeudev-project:masterfrom
bbonev:fix-free-nonheap-object
Oct 3, 2022
Merged

Do not free a static string#238
bbonev merged 3 commits intoeudev-project:masterfrom
bbonev:fix-free-nonheap-object

Conversation

@bbonev
Copy link
Member

@bbonev bbonev commented Sep 21, 2022

In file included from udevadm-hwdb.c:26:
In function ‘freep’,
inlined from ‘adm_hwdb’ at udevadm-hwdb.c:624:38:
../../src/shared/util.h:289:9: warning: ‘free’ called on a pointer to an unallocated object ‘"/usr/etc/udev/hwdb.bin"’ [-Wfree-nonheap-object]
289 | free(*(void**) p);
| ^~~~~~~~~~~~~~~~~
../../src/shared/util.h:289:9: warning: ‘free’ called on a pointer to an unallocated object ‘"/usr/etc/udev/hwdb.bin"’ [-Wfree-nonheap-object]

In file included from udevadm-hwdb.c:26:
In function ‘freep’,
    inlined from ‘adm_hwdb’ at udevadm-hwdb.c:624:38:
../../src/shared/util.h:289:9: warning: ‘free’ called on a pointer to an unallocated object ‘"/usr/etc/udev/hwdb.bin"’ [-Wfree-nonheap-object]
  289 |         free(*(void**) p);
      |         ^~~~~~~~~~~~~~~~~
../../src/shared/util.h:289:9: warning: ‘free’ called on a pointer to an unallocated object ‘"/usr/etc/udev/hwdb.bin"’ [-Wfree-nonheap-object]
@ArsenArsen
Copy link
Collaborator

There's a bit more work to consider, the string is reassigned later down the function.

@bbonev
Copy link
Member Author

bbonev commented Sep 21, 2022

Thanks! Looks like I missed that...

- the value is unused anyways
- thanks to Arsen for spotting this

In file included from udevadm-hwdb.c:26:
In function ‘freep’,
    inlined from ‘adm_hwdb’ at udevadm-hwdb.c:624:38:
../../src/shared/util.h:289:9: warning: ‘free’ called on a pointer to an unallocated object ‘"/usr/etc/udev/hwdb.bin"’ [-Wfree-nonheap-object]
  289 |         free(*(void**) p);
      |         ^~~~~~~~~~~~~~~~~
../../src/shared/util.h:289:9: warning: ‘free’ called on a pointer to an unallocated object ‘"/usr/etc/udev/hwdb.bin"’ [-Wfree-nonheap-object]
@bbonev
Copy link
Member Author

bbonev commented Oct 3, 2022

Please check it again with the last commits...

Copy link
Collaborator

@ArsenArsen ArsenArsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, sorry, I saw the email but forgot; this should be fine (_cleanup_free_ calls freep calls free, which is defined to be no-op on NULL)

@bbonev bbonev merged commit 99b0381 into eudev-project:master Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants