From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <375gnu@gmail.com> X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Status: No, score=-0.1 required=3.0 tests=AWL,BAYES_00,FREEMAIL_FROM, FROM_STARTS_WITH_NUMS,RCVD_IN_DNSWL_BLOCKED,URIBL_BLOCKED shortcircuit=no autolearn=no version=3.3.2 X-Original-To: kgio-public@bogomips.org Received: from mail-pd0-f172.google.com (mail-pd0-f172.google.com [209.85.192.172]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id D808B1FA6C for ; Tue, 30 Dec 2014 07:40:43 +0000 (UTC) Received: by mail-pd0-f172.google.com with SMTP id y13so18764250pdi.31 for ; Mon, 29 Dec 2014 23:40:43 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.68.208.65 with SMTP id mc1mr95860943pbc.111.1419925243233; Mon, 29 Dec 2014 23:40:43 -0800 (PST) Received: by 10.70.97.111 with HTTP; Mon, 29 Dec 2014 23:40:43 -0800 (PST) In-Reply-To: References: Date: Tue, 30 Dec 2014 10:40:43 +0300 Message-ID: Subject: Re: programs using kgio crash under memory pressure during init From: Hleb Valoshka <375gnu@gmail.com> To: Petr Novodvorskiy Cc: kgio-public@bogomips.org, Lara Martin , Nick Astete Content-Type: text/plain; charset=UTF-8 List-Id: On 12/30/14, Petr Novodvorskiy wrote: > After looking in the code, I think I was able to identify the problem. In > init_kgio_tryopen(), when rb_funcall is called to get list of errno > constants, it doesn't protect returned list from garbage collecting. I made > modification (below) that seemed to fix the problem (I wasn't able to > reproduce it anymore). > + tmp = rb_protect(get_err_constants, (VALUE)NULL, &exception); I don't know why does it help, but rb_protect is wrong function for your purpose: VALUE rb_protect(VALUE (*func) (VALUE), VALUE arg, int *state) Calls the function func with arg as the argument. If no exception occured during func, it returns the result of func and *state is zero. Otherwise, it returns Qnil and sets *state to nonzero. If state is NULL, it is not set in both cases. You have to clear the error info with rb_set_errinfo(Qnil) when ignoring the caught exception.