Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID
	autolearn=ham autolearn_force=no version=3.4.1
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=brasslantern-com.20150623.gappssmtp.com; s=20150623;
        h=from:message-id:date:in-reply-to:comments:references:to:subject
         :mime-version;
        bh=7ALrzFKcai5ZICq4zAJSZuixnUWRSU3z6i7rgfMBP5U=;
        b=OTTgx0Rgz8YMQP5MiER8a0l55hgkc0XeP4S2c0X4zhoMXNZnMxDkc/Wkc5LQZmN8OJ
         oTyxTBVgek0Anzjmbtlh+LezcKln01t0+E0MAmp7NMTI1TiJ55aajuASKnSOWBtrfjT4
         8gPzp0W7fF7SnKdiKvgEgtZME9Xmr7eIhFzeT0k6z+lX+3qTjofVQ8ErEr2uPt6trOuP
         xeRQRPcgLc+97UpeWRxvMrlBqQ08deuA017G+PrzvhTxbbxFyZ/Q+OgCb7fusrvoe7c3
         yNgSFxo4TuSyYKd47ghe4mJjNxRoXEEjFB6NlhlOvmQDE3DdniYCYioPGfIuZ4gVkX83
         gGLg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:message-id:date:in-reply-to:comments
         :references:to:subject:mime-version;
        bh=7ALrzFKcai5ZICq4zAJSZuixnUWRSU3z6i7rgfMBP5U=;
        b=BB0W5xqQvPIT9mhyAUKqT18MuFzxTU3bogDd9sx1wF3Tvrmpqkj0t2oocTQoR/5ayr
         VfWyWhSxlcer04qLQ6Avux1qSeGRPN0GfPabCTXXXspVHVZKbBxG13VJrHJ6dh454kbL
         yP+8FP4i2afHwkBAXrbNmX5hnkbGvk5i8TupmwUp2UU7RF2/kLXsJkcxxElXNi7QH+yN
         NjRWvgQf98/iD5ISBqhiJzQSa31uV16EFq32VzII22jOE6A44eh+wef+ORTGRhcW8ni6
         +4X3jxZGhu72vIKg0KAagMqDyC8E9WdisdQIy9kVN3+kNsMys2HEcKiaT22AqeqgPJKA
         8Yow==
X-Gm-Message-State: AD7BkJIvE06WzaMflEdUkt1BXhHi96Ef9+fw2kMRsefwl/T2Ru+w65LH4fkmw+QlVsbAsg==
X-Received: by 10.66.243.35 with SMTP id wv3mr45975960pac.93.1458573001725;
        Mon, 21 Mar 2016 08:10:01 -0700 (PDT)
From: Bart Schaefer <schaefer@brasslantern.com>
Message-Id: <160321081031.ZM25709@torch.brasslantern.com>
Date: Mon, 21 Mar 2016 08:10:31 -0700
In-Reply-To: <20160321104301.0ff32aae@pwslap01u.europe.root.pri>
Comments: In reply to Peter Stephenson <p.stephenson@samsung.com>
        "Re: access already freed memory when resize window" (Mar 21, 10:43am)
References: <CAKzW8okOFzO=ZNdi4HkKuQDnDdqAkQELmXGYJ3XSoho_kvJNzw@mail.gmail.com> 
	<160320101910.ZM8306@torch.brasslantern.com> 
	<20160321104301.0ff32aae@pwslap01u.europe.root.pri>
X-Mailer: OpenZMail Classic (0.9.2 24April2005)
To: zsh-workers@zsh.org
Subject: Re: access already freed memory when resize window
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Seq: zsh-workers 38196

On Mar 21, 10:43am, Peter Stephenson wrote:
} Subject: Re: access already freed memory when resize window
}
} On Sun, 20 Mar 2016 10:19:10 -0700
} Bart Schaefer <schaefer@brasslantern.com> wrote:
} > It doesn't even help to queue signals, because waiting for the command
} > substitution to finish must temporarily unqueue them.
} 
} Right, but shouldn't there at least be some attempt to tame the points
} at which recursion can happen?  Or is that already happening, and all
} the effects we're seeing are out at the top level after the signal
} handler has returned?

Generically, the problem is that reexpandprompt() was doing

	free(GlobalPointer);
	GlobalPointer = maybe_reference_GlobalPointer();

The fact that the reference is from a signal handler is an instantiation
of "maybe".  So at the very least we have to change the order of the
function call and the free.

An added complication is that we have two interdependent global pointers
that were both being treated that way.

To "tame the recursion" we could do something like this:

 #ifdef SIGWINCH
     case SIGWINCH:
+	winch_block();
         adjustwinsize(1);  /* check window size and adjust */
 	(void) handletrap(SIGWINCH);
+	winch_unblock();
         break;
 #endif
 
But then we might stop adjusting our idea of the window size before the
user stops resizing the window.  (Also due to the way we manage signal
queuing we don't know the current state of winch_block() at that point,
so it might not be correct to block/unblock.  The whole winch-handling
scheme would have to be revised to be more like queue_signals().)

