Code: store_pool_delete(png_store *ps, store_pool *pool)
{
 if (pool->list != NULL)
 {
      fprintf(stderr, "%s: %s %s: memory lost (list follows):\n", ps->test,
         pool == &ps->read_memory_pool ? "read" : "write",
         pool == &ps->read_memory_pool ? (ps->current != NULL ?
            ps->current->name : "unknown file") : ps->wname);
 ++ps->nerrors;

 do
 {
         store_memory *next = pool->list;
         pool->list = next->next;

          next->next = NULL;
 
          fprintf(stderr, "\t%lu bytes @ %p\n",
             (unsigned long)next->size, (PNG_CONST void*)(next+1));
          /* The NULL means this will always return, even if the memory is
           * corrupted.
           */
         store_memory_free(NULL, pool, next);
 }
 while (pool->list != NULL);
 }

 /* And reset the other fields too for the next time. */
 if (pool->max > pool->max_max) pool->max_max = pool->max;
   pool->max = 0;
 if (pool->current != 0) /* unexpected internal error */
      fprintf(stderr, "%s: %s %s: memory counter mismatch (internal error)\n",
         ps->test, pool == &ps->read_memory_pool ? "read" : "write",
         pool == &ps->read_memory_pool ? (ps->current != NULL ?
            ps->current->name : "unknown file") : ps->wname);
   pool->current = 0;

 if (pool->limit > pool->max_limit)
      pool->max_limit = pool->limit;

   pool->limit = 0;

 if (pool->total > pool->max_total)
      pool->max_total = pool->total;

   pool->total = 0;

 /* Get a new mark too. */
   store_pool_mark(pool->mark);
}

Vulnerability Type: +Priv 
CWE ID: 
Summary: Unspecified vulnerability in libpng before 1.6.20, as used in Android 4.x before 4.4.4, 5.0.x before 5.0.2, 5.1.x before 5.1.1, and 6.x before 2016-07-01, allows attackers to gain privileges via a crafted application, as demonstrated by obtaining Signature or SignatureOrSystem access, aka internal bug 23265085.
Commit Message: DO NOT MERGE Update libpng to 1.6.20

BUG:23265085
Change-Id: I85199805636d771f3597b691b63bc0bf46084833
(cherry picked from commit bbe98b40cda082024b669fa508931042eed18f82)
