git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 10/11] read-cache.c: fix memory leaks caused by removed cache entries

From
Thomas Rast <tr@thomasrast.ch>
Date
Oct 19, 2013, 19:28 UTC
Message-ID
<8738nx2h70.fsf@thomasrast.ch>
In-Reply-To
<524A9886.2030508@gmail.com>
Karsten Blees <karsten.blees@gmail.com> writes:
Show 10 quoted lines
> When cache_entry structs are removed from index_state.cache, they are not
> properly freed. Freeing those entries wasn't possible before because we
> couldn't remove them from index_state.name_hash.
>
> Now that we _do_ remove the entries from name_hash, we can also free them.
> Add free(cache_entry) to all call sites of name-hash.c::remove_name_hash in
> read-cache.c, as name-hash.c isn't concerned with cache_entry allocation.
>
> cmd_rm and unmerge_index_entry_at use cache_entry.name after removing the
> entry. Copy the name so that we don't access memory that has been freed.

Is this the version that is currently in pu? There's a valgrind test failure in current pu that bisects to 36850edb, which would seem to be from this email but doesn't have the right author date. Worse, I cannot apply this on top of 36850edb^ because I don't have the 'index' blobs for this patch. Confusing.

In any case 36850edb currently breaks several valgrind tests. You can valgrind only t6022.16 like so (that one test is sufficient to track it down and it's much faster that way):

  cd t  
  ./t6022-merge-rename.sh --valgrind-only=16
The valgrind error in t6022.16 looks like this:
  ==4959== Invalid read of size 1
  ==4959==    at 0x5682A38: vfprintf (vfprintf.c:1629)
  ==4959==    by 0x56AC564: vsnprintf (vsnprintf.c:119)
  ==4959==    by 0x542005: vreportf (usage.c:12)
  ==4959==    by 0x54216C: error_builtin (usage.c:42)
  ==4959==    by 0x54261B: error (usage.c:147)
  ==4959==    by 0x4FC681: read_index_unmerged (read-cache.c:1900)
  ==4959==    by 0x475CF1: reset_index (reset.c:68)
  ==4959==    by 0x476A72: cmd_reset (reset.c:346)
  ==4959==    by 0x405999: run_builtin (git.c:314)
  ==4959==    by 0x405B2C: handle_internal_command (git.c:477)
  ==4959==    by 0x405C46: run_argv (git.c:523)
  ==4959==    by 0x405DE2: main (git.c:606)
  ==4959==  Address 0x5bedb54 is 84 bytes inside a block of size 104 free'd
  ==4959==    at 0x4C2ACDA: free (vg_replace_malloc.c:468)
  ==4959==    by 0x4F9360: remove_index_entry_at (read-cache.c:482)
  ==4959==    by 0x4FA469: add_index_entry_with_check (read-cache.c:964)
  ==4959==    by 0x4FA5A4: add_index_entry (read-cache.c:993)
  ==4959==    by 0x4FC663: read_index_unmerged (read-cache.c:1899)
  ==4959==    by 0x475CF1: reset_index (reset.c:68)
  ==4959==    by 0x476A72: cmd_reset (reset.c:346)
  ==4959==    by 0x405999: run_builtin (git.c:314)
  ==4959==    by 0x405B2C: handle_internal_command (git.c:477)
  ==4959==    by 0x405C46: run_argv (git.c:523)
  ==4959==    by 0x405DE2: main (git.c:606)
If you need any more information/help, just ask :-)
-- 
Thomas Rast
tr@thomasrast.ch
Previous: Karsten BleesNext: Karsten Blees
Message 12 of 14 in “New hash table implementation”
  1. 00/11 New hash table implementationKarsten Blees, Oct 1, 2013
  2. 01/11 add a hashtable implementation that supports O(1) removalKarsten Blees, Oct 1, 2013
  3. 02/11 buitin/describe.c: use new hash map implementationKarsten Blees, Oct 1, 2013
  4. 03/11 diffcore-rename.c: move code around to prepare for the next patchKarsten Blees, Oct 1, 2013
  5. 04/11 diffcore-rename.c: simplify finding exact renamesKarsten Blees, Oct 1, 2013
  6. 05/11 diffcore-rename.c: use new hash map implementationKarsten Blees, Oct 1, 2013
  7. 06/11 name-hash.c: use new hash map implementation for directoriesKarsten Blees, Oct 1, 2013
  8. 07/11 name-hash.c: remove unreferenced directory entriesKarsten Blees, Oct 1, 2013
  9. 08/11 name-hash.c: use new hash map implementation for cache entriesKarsten Blees, Oct 1, 2013
  10. 09/11 name-hash.c: remove cache entries instead of marking them CE_UNHASHEDKarsten Blees, Oct 1, 2013
  11. 10/11 read-cache.c: fix memory leaks caused by removed cache entriesKarsten Blees, Oct 1, 2013
  12. Thomas RastOct 19, 2013
  13. fixup! read-cache.c: fix memory leaks caused by removed cache, entriesKarsten Blees, Oct 22, 2013
  14. 11/11 remove old hash.[ch] implementationKarsten Blees, Oct 1, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.