flak rss random

memory leak proof every C program

Memory leaks have plagued C programs for as long as the language has existed. Many solutions have been proposed, even going so far as to suggest we should rewrite C programs in other languages. But there’s a better way.

Presented here is a simple solution that will eliminate the memory leaks from every C program. Link this into your program, and memory leaks are a thing of the past.

leakproof.c
#include <dlfcn.h>
#include <stdio.h>

struct leaksaver {
        struct leaksaver *next;
        void *pointer;
} *bigbucket;

void *
malloc(size_t len)
{
        static void *(*nextmalloc)(size_t);
        nextmalloc = dlsym(RTLD_NEXT, "malloc");
        void *ptr = nextmalloc(len);
        if (ptr) {
                struct leaksaver *saver = nextmalloc(sizeof(*saver));
                saver->pointer = ptr;
                saver->next = bigbucket;
                bigbucket = saver;
        }
        return ptr;
}


Every allocated pointer is saved in the big bucket, where it remains accessible. Even if no other references to the pointer exist in the program, the pointer has not leaked.

It is now entirely optional to call free. If you don’t call free, memory usage will increase over time, but technically, it’s not a leak. As an optimization, you may choose to call free to reduce memory, but again, strictly optional.

Problem sovled!

Posted 19 Jan 2024 16:55 by tedu Updated: 19 Jan 2024 16:55
Tagged: c programming rants

from apples to pears

Here at Enterprising Enterprise, we love technology, but we’re also pushing it hard, constantly trying to expand the frontier of what’s possible. Along the way, we frequently find we’ve outgrown an earlier technology choice, and it’s time for us to migrate to something new. There’s a cost to doing this, but it’s the only way to keep moving forward.

more...

Posted 17 Jun 2022 06:53 by tedu Updated: 17 Jun 2022 06:53
Tagged: rants

virtualization in windows

My Windows desktop has a Threadripper CPU with a few cores. Maybe I could I get a bit more utilization out of it with virtualization. Or maybe, given the frequency with which attacks target Windows, I could use virtualization to increase security. Let’s see how that goes.

more...

Posted 06 Apr 2020 07:45 by tedu Updated: 06 Apr 2020 07:45
Tagged: rants software

how to read a blog post that omits explanation

Some people write blog posts. Some people read blog posts. Sometimes readers find that the writers do not explain everything they expected to be explained. I typically prefer to write about things other than my own writing, but occasionally there are exceptions.

more...

Posted 05 Sep 2019 15:33 by tedu Updated: 05 Sep 2019 15:34
Tagged: rants

github ui

I’ve been paying a bit more attention than usual to web interfaces, and there’s a few examples which really get to me. GitHub is one that’s annoyed me for a while, but I didn’t quite know what was wrong until I looked at some screenshots to see what was frustrating me.

more...

Posted 13 Feb 2019 23:08 by tedu Updated: 14 Feb 2019 17:39
Tagged: rants web

but what about screen readers

But what about screen readers, you ask. Somebody did a web thing you don’t like. Doesn’t this break screen readers?

It seems the easy way to find out would be to test. But that requires caring about screen reader usability enough to actually have one on hand to test. Much easier to wag fingers. Screen readers are the starving children of web accessibility arguments. Why don’t you care about the starving children?

It’s borrowing somebody else’s concerns to score internet points. Oh, hi, I just wanted to try this on and post a few comments, you can have it back now. Thanks. I wouldn’t want to have to think about this all the time.

Posted 08 Feb 2019 18:02 by tedu Updated: 08 Feb 2019 18:02
Tagged: rants web

two dollars to choose

Configuring an HP laptop, came across this gem.

two dollar choice

I like that I get a choice, but is it really necessary to tack on a $2 fee? If I have to choose one or the other, maybe just include it in the listed price? I thought airlines were bad...

Possibly related to this great option:

wifi yes or yes

It’s a tough choice, but somebody has to make it. And pay $22 for the privilege.

Posted 11 Jul 2017 07:20 by tedu Updated: 11 Jul 2017 18:11
Tagged: business rants

hard facts about shitcoins

Got a new spam today, subject “hard facts”, which was actually kind of interesting. There was a link, which obviously not clicking, but the body was a reply to an email I had allegedly sent. Here’s what I said:

Be careful with shitcoins. They tend to market themselves based on the latest trendy arguments against btc.

First it was the confirmation time then mining algorithm then inflation schedule
and recently, unfairly distributed, incomplete shitcoins are hyped on the grounds
of smart contracts, usually asking you to buy in their "crowdsale" or "IPO".

That’s so on target I thought maybe it really was an email I’d sent. Is it still spam if I agree with it?

Posted 30 Jun 2017 19:48 by tedu Updated: 30 Jun 2017 19:48
Tagged: mailfail rants

HP Chrome Print fuckup du jour

Long story short, printing on a chromebook is still fucked, and now the incompetent dickheads who write drivers for HP have made things worse. With time and effort, however, one can still repair the damage. Writing this up in case somebody finds it useful, and because I have little doubt I’ll be referring to it again in the near future.

First, the problem: printing from a chromebook to a local network printer no longer works. There is an extension that used to make this possible. If one reads the reviews, one will quickly notice the many, many one star reviews saying that it doesn’t work. In particular, it used to work, but after the March 20 update it completely unhelpfully and uselessly does nothing but say “Printing unsuccessful”. That was more than a month ago. The rockstar talent at HP is apparently on tour and too busy to fix this.

Here’s the insane workaround. First we need the old version of the extension. Obviously Google will never let us have it, but there’s an archive site. Here’s the previous print extension. Download that. Rename the file to zip. Create a new folder and extract the contents of the zip file. Rename the _metadata folder to not_metadata. Open the chrome extensions panel. Delete the old HP Print extension. Flip into developer mode. Add an unpacked extension. Add back the printer IP address and rejoice.

For bonus fun, talk your mom through this procedure over the phone.

Posted 30 Apr 2017 22:00 by tedu Updated: 30 Apr 2017 22:00
Tagged: bugs rants software web

careful with the chrome HSTS

Updated to chrome and noticed I couldn’t login to my own site.

www.tedunangst.com normally uses encryption to protect your information. When Google Chrome tried to connect to www.tedunangst.com this time, the website sent back unusual and incorrect credentials.

That’s mostly not wrong, although the “this time” is. The cert has never been fully trusted by chrome, but I click through because I’m a bad person. This time, however, there was no option to do so.

You cannot visit www.tedunangst.com right now because the website uses HSTS.

I mean, yes, I set the HSTS header, but that was with the same cert that chrome is now insisting can’t be trusted. Why in the world would you permanently store “must have trusted cert” on the basis of an untrusted cert?

I suppose this warning is too late to save anyone, but you can clear HSTS sites if necessary via chrome://net-internals/#hsts.

Posted 14 Apr 2017 18:59 by tedu Updated: 14 Apr 2017 18:59
Tagged: bugs rants web