zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-workers@zsh.org
Subject: Re: [PATCH] db/gdbm rewrite
Date: Thu, 16 Feb 2017 12:52:15 +0000	[thread overview]
Message-ID: <20170216125215.1b744bf6@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <1487245575.1843244.882932424.59844A89@webmail.messagingengine.com>

On Thu, 16 Feb 2017 03:46:15 -0800
Sebastian Gniazdowski <psprint2@fastmail.com> wrote:
> – The parameter "testkey" in the hash should be empty as it is its first
> use. It comes from getgdbmnode():
>         val_pm = (Param) zshcalloc( sizeof (*val_pm) );
>         val_pm->node.flags = PM_SCALAR | PM_HASHELEM; /* no PM_UPTODATE
>         */
>         val_pm->gsu.s = (GsuScalar) ht->tmpdata;
>         ht->addnode( ht, ztrdup( name ), val_pm ); // sets pm->node.nam
> 
> – zshcalloc() should result in "pm->u.str" to be set to NULL
> 
> – so the "first zsfree() in gdbmsetfn()" should not run:
>     if (pm->u.str) {
>         zsfree(pm->u.str);
>         ...

The parameter in question at the point of the error contains

$1 = {node = {next = 0x0, nam = 0x8d7d9c8 "testkey", flags = 537395200}, u = {data = 0x8d7d8b8, arr = 0x8d7d8b8, str = 0x8d7d8b8 "testdata", val = 148363448, valptr = 0x8d7d8b8, dval = 7.3301282755354198e-316, hash = 0x8d7d8b8}, gsu = {s = 0x8dfb540, i = 0x8dfb540, f = 0x8dfb540, a = 0x8dfb540, h = 0x8dfb540}, base = 0, width = 0, env = 0x0, ename = 0x0, old = 0x0, level = 0}

I'm guessing this must be a node within the hash, not the hash itself.

I think this is because the file already exists... Yep, I only get the
error the second time I run the code, so my information was incomplete.
The original allocation will have been at whatever point the internal
hash entries were set up.  So you need to check what length that was
(should be 9 for zsfree() to work on "testdata").

In non-zsh malloc, zsfree() simply dispatches to free() and doesn't care
about the size of the string.

However, replacing all the zsfree()s with free gave me an infinite loop
on a free.  This was at free(umkey) inside the braces (the first
of the two) in gdbmgetfn().  So the internal calculation of what needs
freeing is definitely getting confused by something that's going on.

I won't have a lot of time to look at this myself.

Evidence the same effect doesn't happen with a different allocator isn't
useful with memory errors, which are very sensitive to internal layout.

pws


  reply	other threads:[~2017-02-16 12:52 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-14 12:20 Sebastian Gniazdowski
2017-02-15 10:22 ` Sebastian Gniazdowski
2017-02-16 10:16   ` Peter Stephenson
2017-02-16 11:46     ` Sebastian Gniazdowski
2017-02-16 12:52       ` Peter Stephenson [this message]
2017-02-16 14:25         ` Sebastian Gniazdowski
2017-02-16 14:30           ` Sebastian Gniazdowski
2017-02-16 15:11             ` Peter Stephenson
2017-02-16 16:03               ` Sebastian Gniazdowski
2017-02-16 16:25                 ` Sebastian Gniazdowski
2017-02-16 16:36                   ` Peter Stephenson
2017-02-16 17:12                     ` Sebastian Gniazdowski
2017-02-16 18:16                 ` Sebastian Gniazdowski
2017-02-19  0:43 (Fwd) " Bart Schaefer
2017-02-19  8:46 ` Sebastian Gniazdowski
2017-02-19 18:19   ` Bart Schaefer
2017-02-20  8:32     ` Sebastian Gniazdowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170216125215.1b744bf6@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).