Debarshi's den


with 4 comments

MALLOC_PERTURB_ is a useful thing. If you are developing on glibc-based systems, I encourage you to put this snippet in your ~/.bash_profile:

MALLOC_PERTURB_=$(($RANDOM % 255 + 1))

I have been using it for the last six years on all my computers (3 laptops running every Fedora x86_64 build released since then), and while things haven’t exploded, it has helped uncover the odd bug every once in a while. One such occasion presented itself this week.

I was busy following Ondrej’s hint, debugging why Eye of GNOME was taking so long to open a file from ownCloud. Imagine my shock when it would just crash after showing the window. The same optimization was working just fine on the gnome-3-18 branch, while master was crashing even without any changes. How could that happen? Obviously, while it was failing for me, it was working fine for all those who run unstable GNOME versions via jhbuild, gnome-continous, Fedora rawhide, etc.. Otherwise we would have been debugging this crash, and not a performance issue.

I guess, most of them didn’t have MALLOC_PERTURB_.

Here is another such story.

In case you were wondering, there is already an update on its way to Fedora 24 address the crash.

Written by Debarshi Ray

9 April, 2016 at 02:28

4 Responses

Subscribe to comments with RSS.

  1. Or you can add this to ~/.jhbuildrc:

    import random
    os.environ[‘MALLOC_PERTURB_’] = str(random.randint(0, 255))

    And use valgrind to debug 🙂

    Bastien Nocera

    9 April, 2016 at 12:15

  2. If you put it into .bashrc how does it affect openssl certificate generation? If I remember correctly one of the causes of the debian certificate debacle was that the package modified the upstream sources to change a read from uninitialized memory (which is undefined according to the C standard) which resulted in a loss of entropy. Setting all newly allocated memory to a uniform value will have a similar effect. Having said that openssl may well have changed since then it was quite a while ago now.

    Phillip Wood

    10 April, 2016 at 11:33

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: