lib/list.c: realloc(3) and memmove(3) to prevent memory leaks#1423
Open
alejandro-colomar wants to merge 4 commits intoshadow-maint:masterfrom
Open
lib/list.c: realloc(3) and memmove(3) to prevent memory leaks#1423alejandro-colomar wants to merge 4 commits intoshadow-maint:masterfrom
alejandro-colomar wants to merge 4 commits intoshadow-maint:masterfrom
Conversation
550cffb to
378deaa
Compare
378deaa to
55b3d70
Compare
c6a7a19 to
ee48f1a
Compare
ee48f1a to
0d2aceb
Compare
c21af3c to
8c95007
Compare
8c95007 to
5e4650e
Compare
5e4650e to
7637356
Compare
d835be3 to
a0a653d
Compare
a0a653d to
b4acf53
Compare
Each call to add_list() that resulted in adding a group to the list was leaking the old list. There's no need to allocate a fresh list. Otherwise, it would be incorrect to return the original pointer in some cases, which we already did. Signed-off-by: Alejandro Colomar <alx@kernel.org>
… avoid memory leaks Like del_list(), each call to del_list() that wasn't a no-op, was leaking the old list. There's no need to allocate a fresh list; we can use memmove(3) to delete the old member, and return the original pointer. We already return the original pointer in some cases, so this must be okay. Signed-off-by: Alejandro Colomar <alx@kernel.org>
69e5f7e to
7920b52
Compare
An interesting detail is that we require the second argument to be non-const, while the memmove(3) function gets a const void*. This is because the second argument should usually be just the same as the first one, plus some offset, and thus will have the same const qualification (that is, it will not be qualified). Don't return anything, as we're not using the return value. That avoids having to use a cast (we can't use a compound literal because of -Werror=unused-value). Signed-off-by: Alejandro Colomar <alx@kernel.org>
This adds type safety. Signed-off-by: Alejandro Colomar <alx@kernel.org>
7920b52 to
1f0428e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Revisions:
v2
v2b
v3
v3b
interdiff
range-diff
v3c
interdiff
range-diff
v3d
interdiff
range-diff
v4
v4b
v5
interdiff
range-diff
v6
v7
v8
v9
const-qualified input.v10
v10b
v10c
v10d
v10e
v11
v11b
v11c
v12
v13
v13b
\from v13.v13c