From: Stefan Beller <hidden> Date: 2016-06-15 23:04:18
Here comes another bunch of memory leaks fixed.
patches 1-4 are safe bets, but 5 and 6 are not so.
In patch 5 I wonder if we need to fix more aggressively and
in patch 6 I just know there is a leak but I have no idea how to
actually fix it.
The patches are apply-able to origin/master.
Version 2 has no changes in code but in recipients. CC'ing parties who
may be qualified to review the patches.
Stefan Beller (6):
shallow: fix a memleak
line-log.c: fix a memleak
line-log.c: fix a memleak
wt-status.c: fix a memleak
pack-bitmap: fix a memleak
WIP/RFC/entry.c: fix a memleak
entry.c | 4 +++-
line-log.c | 4 ++++
pack-bitmap.c | 27 ++++++++++++++++++---------
shallow.c | 4 ++--
wt-status.c | 2 ++
5 files changed, 29 insertions(+), 12 deletions(-)
--
2.3.0.81.gc37f363
From: Stefan Beller <hidden> Date: 2016-06-15 23:04:18
The `filepair` is assigned new memory with any iteration via
process_diff_filepair, so free it before the current iteration ends.
Signed-off-by: Stefan Beller <redacted>
---
line-log.c | 1 +
1 file changed, 1 insertion(+)
From: Stefan Beller <hidden> Date: 2016-06-15 23:04:18
I observe that filter is going out of scope, but the
implementation proposed in this patch produces just a
crash instead of any helpful fix.
Signed-off-by: Stefan Beller <redacted>
---
entry.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
From: Stefan Beller <hidden> Date: 2016-06-15 23:04:18
In any code path of shorten_unambiguous_ref the return value is a
xstrdup(some string), so it is safe to free the variable `base`
in any codepath.
Signed-off-by: Stefan Beller <redacted>
---
wt-status.c | 2 ++
1 file changed, 2 insertions(+)
From: Stefan Beller <hidden> Date: 2016-06-15 23:04:18
`recent_bitmaps` is allocated in the function load_bitmap_entries_v1
and it is not passed into any function, so it's safe to free it before
leaving that function.
Signed-off-by: Stefan Beller <redacted>
---
Notes:
I wonder however if we need to free the actual bitmaps
stored in the recent_bitmaps as well.
pack-bitmap.c | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)
Rather than slapping on a band-aid, a cleaner fix would be to move the
allocation of 'tmp' below this conditional since 'tmp' is never used
before the point of this early return.
Perhaps also move allocation of 'bitmap' below the early return (if
you find that it's safe to do so).
From: Eric Sunshine <hidden> Date: 2016-06-15 23:04:18
On Fri, Mar 27, 2015 at 6:32 PM, Stefan Beller [off-list ref] wrote:
quoted hunk
In any code path of shorten_unambiguous_ref the return value is a
xstrdup(some string), so it is safe to free the variable `base`
in any codepath.
Signed-off-by: Stefan Beller <redacted>
---
wt-status.c | 2 ++
1 file changed, 2 insertions(+)
There's an early 'return' before this point (at line 1560) which will
leak 'base', so this is an unreliable fix. A better solution would be
to free(base) immediately after it's final use (before the early
'return').
From: Eric Sunshine <hidden> Date: 2016-06-15 23:04:18
On Fri, Mar 27, 2015 at 6:32 PM, Stefan Beller [off-list ref] wrote:
quoted hunk
`recent_bitmaps` is allocated in the function load_bitmap_entries_v1
and it is not passed into any function, so it's safe to free it before
leaving that function.
Signed-off-by: Stefan Beller <redacted>
---
From: Eric Sunshine <hidden> Date: 2016-06-15 23:04:18
On Fri, Mar 27, 2015 at 6:32 PM, Stefan Beller [off-list ref] wrote:
quoted hunk
I observe that filter is going out of scope, but the
implementation proposed in this patch produces just a
crash instead of any helpful fix.
Signed-off-by: Stefan Beller <redacted>
---
@@ -152,8 +152,10 @@ static int write_entry(struct cache_entry *ce,if(filter&&!streaming_write_entry(ce,path,filter,state,to_tempfile,-&fstat_done,&st))+&fstat_done,&st)){+free_stream_filter(filter);
Aside from the crash you are seeing, this is a bogus fix anyway.
You're only freeing 'filter' if it was allocated _and_ if
streaming_write_entry() returned 0. I would guess your intention was
to free 'filter' regardless of the result of streaming_write_entry().
From: Eric Sunshine <hidden> Date: 2016-06-15 23:04:18
On Friday, March 27, 2015, Eric Sunshine [off-list ref] wrote:
On Fri, Mar 27, 2015 at 6:32 PM, Stefan Beller [off-list ref] wrote:
quoted
I observe that filter is going out of scope, but the
implementation proposed in this patch produces just a
crash instead of any helpful fix.
Signed-off-by: Stefan Beller <redacted>
---
@@ -152,8 +152,10 @@ static int write_entry(struct cache_entry *ce,if(filter&&!streaming_write_entry(ce,path,filter,state,to_tempfile,-&fstat_done,&st))+&fstat_done,&st)){+free_stream_filter(filter);
Aside from the crash you are seeing, this is a bogus fix anyway.
You're only freeing 'filter' if it was allocated _and_ if
streaming_write_entry() returned 0. I would guess your intention was
to free 'filter' regardless of the result of streaming_write_entry().
Unless streaming_write_entry() is freeing the filter for you -- there
is a free_stream_filter() call in close_method_decl() in streaming.c
-- in which case your new free_stream_filter() call would attempt to
free the already-freed filter.
From: John Keeping <hidden> Date: 2016-06-15 23:04:18
On Fri, Mar 27, 2015 at 08:14:28PM -0400, Eric Sunshine wrote:
On Friday, March 27, 2015, Eric Sunshine [off-list ref] wrote:
quoted
On Fri, Mar 27, 2015 at 6:32 PM, Stefan Beller [off-list ref] wrote:
quoted
I observe that filter is going out of scope, but the
implementation proposed in this patch produces just a
crash instead of any helpful fix.
Signed-off-by: Stefan Beller <redacted>
---
@@ -152,8 +152,10 @@ static int write_entry(struct cache_entry *ce,if(filter&&!streaming_write_entry(ce,path,filter,state,to_tempfile,-&fstat_done,&st))+&fstat_done,&st)){+free_stream_filter(filter);
Aside from the crash you are seeing, this is a bogus fix anyway.
You're only freeing 'filter' if it was allocated _and_ if
streaming_write_entry() returned 0. I would guess your intention was
to free 'filter' regardless of the result of streaming_write_entry().
Unless streaming_write_entry() is freeing the filter for you -- there
is a free_stream_filter() call in close_method_decl() in streaming.c
-- in which case your new free_stream_filter() call would attempt to
free the already-freed filter.
Yes, I think the correct fix for this leak is to make
stream_blob_to_fd() always free the filter, since there's only one path
out that doesn't at the moment and there's no way for the caller to
figure out whether or not the filter has been freed:
-- >8 --
From: Jeff King <hidden> Date: 2016-06-15 23:04:19
On Fri, Mar 27, 2015 at 03:32:48PM -0700, Stefan Beller wrote:
`recent_bitmaps` is allocated in the function load_bitmap_entries_v1
and it is not passed into any function, so it's safe to free it before
leaving that function.
I think this is OK, though it might be easier still to just turn the
array into a stack variable. It's only 160 * sizeof(ptr), or about 1280
bytes on a 64-bit system. Note that the xcalloc there looks wrong (it is
way over-allocating by using the sizeof the struct, not a pointer to the
struct).
Notes:
I wonder however if we need to free the actual bitmaps
stored in the recent_bitmaps as well.
No, those are just weak pointers. The memory is owned by the hash that
store_bitmap puts the bitmaps into.