Latest Publications

Debug your “double free or corruption” errors

I’ve seen a couple of instances now where people are using delete or free for IplImages. This will, as far as I know, always result in a memory error at runtime, which on Ubuntu, looks something like this:


*** glibc detected *** ./analyser: double free or corruption (out): 0x09b0ef50 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6[0x2867ff1]
/lib/tls/i686/cmov/libc.so.6[0x28696f2]
/lib/tls/i686/cmov/libc.so.6(cfree+0x6d)[0x286c7cd]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0xeb76f1]
./analyser(_ZN12bct_analysis12processImageEPK9_IplImageiiii+0x80)[0x804d12b]
./analyser(main+0x6f2)[0x804abb6]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0x2813b56]
./analyser[0x804a431]
======= Memory map: ========
00110000-001a3000 r-xp 00000000 08:01 5861 /usr/lib/libgio-2.0.so.0.2200.3
001a3000-001a4000 r--p 00092000 08:01 5861 /usr/lib/libgio-2.0.so.0.2200.3
001a4000-001a5000 rw-p 00093000 08:01 5861 /usr/lib/libgio-2.0.so.0.2200.3

So, we can see from the error the cause is “double free or corruption” in libc. This error isn’t unique to OpenCV and is discussed in a lot of places. For some reason a frequently recommended fix for this seems to be to disable memory error checks by setting the environment variable MALLOC_CHECK_.

facepalm

Errors and warning messages are your friends. Very rarely should you suppress such messages and hope for the best. The only acceptable time to ignore them is when you’ve made promises about being finished, you’re due to deliver and you’re pretty sure you can get a bug fix out before someone notices. Or if it’s nearly lunch time. Of course, desktop users who just want to get on with using some program, you’ve done nothing wrong – feel free to blithely carry on!

The “error” is caused by glibc’s mcheck. The best solution is to debug your code. IDEs like Netbeans and (*sigh*) eclipse make this pretty trivial. If you’re too cool for X gdb is easy enough to get to grips with, and is what underlies the graphical environments anyway. Personally, I like Valgrind for memory and profiling issues; though in many cases simple code stepping will hopefully make multiple uses of free apparent.

mcheck is purely diagnostic, if a little invasive, more iformation can be found in the glibc documentation and man 3 of malloc:

If MALLOC_CHECK_ is set to 0, any detected heap corruption is silently ignored; if set to 1, a diagnostic message is printed on stderr; if set to 2, abort(3) is called immediately; if set to 3, a diagnostic message is printed on stderr and the program is aborted.

Double freeing can have unpredictable behaviour. Admittedly in many cases it will can go unnoticed, but why risk it? Buffer overflows and corruption of memory structures can occur and cause drastic failure.

In the case of delete/free with OpenCV the solution is to use the provided cvReleaseImage() for C (or Mat::release() in C++). OpenCV has internal allocate and free functions (which are by default malloc and free, wrapped in some magic); which is always best, particularly when dealing with complex types where pointer-to-pointer members may occur.

What would you do for x-ray vision?

As I cleaned the inside of the microwave with an overly damp cloth I had a sudden fear that the excess water may come into contact with unisolated electrical components in the machine. Briefly I was concerned about the risk of shock but this was quickly forgotten when I realised that it’s accidents such as these when super human powers are gained.

It’s well known that a variety of waves in the electromagnetic spectrum are a common cause for the development of super powers. So I soldiered on with the treacherous task in the hope of mutant abilities.

I wonder where the limits are when it comes to the chance of developing super powers? I think I’d risk getting struck by lightning or or being caught in the middle of a freak lab accident.

Agile software development is a sordid conspiracy

As a software engineering student I’m a keen believer in stability, efficacy and efficiency in development. Now, granted, different projects benefit from different development models; ranging from formal techniques for critical systems to more fluid techniques for fast-paced projects. However, the more I think about it the more I wonder if “agile methods” aren’t just a big middle finger to serious development.

Below, I’ve prodived my own exposition of the key principles behind the agile manifesto

Our highest priority is to satisfy the customer through early and continuous delivery of valuable software.
Look at the pretty! We do good?

Welcome changing requirements, even late in development. Agile processes harness change for the customer’s competitive advantage.
Design plans are for people who don’t think they aren’t sure they know what they’ve been asked for.

Deliver working software frequently, from a couple of weeks to a couple of months, with a preference to the shorter timescale.
Get off my back! It sort of works, see?

Business people and developers must work together daily throughout the project.
Working together means meetings. Meetings means more biscuits and less time doing real work. Actually, let’s meet at the pub, it’s a more relaxed environment and will be conducive to our working together!

Build projects around motivated individuals. Give them the environment and support they need, and trust them to get the job done.
Don’t look over my shoulder, I’m playing FarmVille.

The most efficient and effective method of conveying information to and within a development team is face-to-face conversation.
I really can’t be bothered reading all those emails.

Working software is the primary measure of progress.
Yeah, it’s working.. apart from the stuff we haven’t done yet.

Agile processes promote sustainable development. The sponsors, developers, and users should be able to maintain a constant pace indefinitely.
Deadlines are, like, so stressful man. Pass the bong.

Continuous attention to technical excellence and good design enhances agility.
I’mma sit here and watch while you make it do stuff.

Simplicity–the art of maximizing the amount of work not done–is essential.
I can’t be bothered.. let’s just keep bugging the customer to show them partial demos so they think they’re getting their money’s worth.

The best architectures, requirements, and designs emerge from self-organizing teams.
Yeah, ummm, I think Terry knows more about that than me.. make him do it.

At regular intervals, the team reflects on how to become more effective, then tunes and adjusts its behavior accordingly.
Does anyone remember the design plan? I think the cleaners wiped it off the board.

I think you’ll agree with me that what the agile manifesto advocates is laziness, waste and lack of direction.

In all seriousness, I think flexible iterative processes with a deployment/release stage are a good thing. But I’d still like some nice and specific design/requirements documentation.

Pair Programming: removing the romance from code

Pair programming is a somewhat of a controversial practice from the agile world of software development. The basic idea is that one person writes code, whilst the other watches; asking questions and making suggestions. This hopefully means that the code is better written, utilises the experience of both programmers and shares knowledge. Personally, I detest it.

Maybe I’m delusionary or maybe I’m old fashioned, but when I write code.. really write code it doesn’t feel precise or calculated or particularly considered; it just flows. I think the sensation is probably similar to how an artist might feel when painting. There seems to be no real awareness of the world, just code pouring out. This is the reason I decided to study computer science, because I wanted to become a career programmer so I could experience the thrills and joys of the practice.

This just can’t happen when another person is present. Sure, we may get involved and enthusiastic about the work, but it isn’t the same. There’s always that nagging feeling of someone else in your periphery.

And it goes deeper than that. You lose your sense of ownership and pride in your work. One of the best sensations when you write code that other people rely upon is having people come to you for help with it. Even if you’ve made a mistake and need to bug fix, you still have a distinct feeling of ownership and pride in your work. When you develop something in a pair you lose some of that. It’s not really your code any more.

In the past what I’ve found best is to write code on my own then have someone else review it (either with or without me beside them). They can then comment and make suggestions. It may not be as thorough as pair programming, but it preserves the passion and romance of your code. Having other people contribute to your code, after the fact, also seems to work for me. I still know what is mine and what I can take pride in.

Michio Kaku – The Greatest Dude in Pop Science?

There aren’t enough celebrity scientists in my opinion. I love Horizon and the similarly veined “popular science” documentaries that appear now and again. Sure, they somewhat romanticise and dramatise science, but it’s good that a wider audience is being exposed to new sciencing. Due to the broad range of disciplines though, presenters are only reappear infrequently. Which is understandable, but it’s a shame since certain presenters add a certain something of themselves; a contagious enthusiasm for science and, thirst for knowledge.

My favourite presenter has to be theoretical physicist Michio Kaku, he’s appeared in, written and presented a number of documentary programs dealing with physics, futurism and transhumanism (most of which involve my personal favourite – computer science); Horizon, 2057 and Time to name a few of my favourites. His venerable Hiro Protagonist appearance combined with his wit and vivacity make all of his writing and presentation irresistable.

I just finished his new book “Physics of the impossible” which was an interesting whirlwhind tour through fundamental physics in the investigation of theoretical technologies like phasers and invisibility. It’s also a stark reminder of the pliable definition of “impossibility”. We will have our flying cars yet!

I think Michio Kaku is a great influence in the world of science and if you haven’t seen or read any of his work, you should do so now!

Oh yeah, and sciencing is a verb; a brilliant one that necessitates you wear a lab coat when using it!

Helios 44m on EOS 450D

Now I’ve had opportunity to take my camera outside, I’ve been keen to look at different lenses. I had been considering the Canon 50mm f/1.8 which is generally seen as the budget protrait lens. However, after meeting someone with a 7D at AberPhotoSoc using a variety of second-hand, contax mounted manual lenses I realised there were lots of nice and cheap options.

I’d never considered using old lenses, mainly due to concern about distance from the sensor and possible issues with vignetting. However, that doesn’t seem to be a problem in the majority of cases. So I bought myself a Helios 44m 58mm f/2 and an m42/EOS adapter, which came to £21 together.

I’ve not used it much yet, but so far, it’s really nice. Anything that’s in focus is outstandingly clear, and when only near objects are focussed, there is a nice bokeh with a spiral quality.

I think getting an m42 adapter has really opened up a world of interesting, cheap and decent lenses and I can’t wait to have a go with some more.

The Tension and The Terror

My steps were quick, my breathing shallow and my heart unsteady. Despite the cold, sweat from my brow rolled into my eyes, stinging and blinding like tears as the wind whipped my skin viciously.

I stopped fast and held my breath as a bloodcurdling scream echoed from the direction of the train station. Images span through my head and I felt every muscle in my body tense. My heart beat loudly within my chest, blood pounded through my head and numbed the sounds from around me. My mind spun and I felt nauseous as my brain created images from the sound of pounding footsteps behind me.

The scream seemed to last forever, so long that I began to relax, and focus. The palpitations eased but the muscles in my back felt rigid; tensed in fear and cold. I shivered as a single bead of sweat ran down my spine.

The scream still rang out and as I calmed I eventually came to realise the noise was nothing more than strong wind whistling through bars in a gate.

And then the aliens arrived.

This is based on a true story. I’m experimenting with descriptive prose for something larger.

Taking some pictures

I finally got to take my 450D outside with AberPhotoSoc, after not leaving my desk for over a month. I got a bit carried away with the advantages of film free photography and managed to blindly take over a thousand pictures in one afternoon; I had hoped to preserve the care/focus I maintained with film. But, I think I got a couple of nice shots anyway and I’ve joined flickr.

Essential words for science writing

Something I’ve learned over the past few months is that scientific papers aren’t about proving or disproving a hypothesis; it’s not about disseminating information. It’s about using as many abstract, esoteric and pretentious words as you can.

Therefore, I endeavour to use all of the following words in my upcoming dissertation, relevant or not:

  • efficacy
  • prominent
  • correllation
  • lateral
  • variation
  • diagnosis
  • Poisson
  • quadrant
  • intensity
  • proximal
  • segmentation
  • clustering
  • warrants
  • elucidate
  • regression
  • cessation
  • thus
  • methodology
  • protocol
  • credence
  • yield
  • I’m looking forward to it. Though, I still need to produce some interesting data to talk about!

    svnadmin dump for backing up your subversion repository

    I’ve started using subversion more frequently now that I’m churning out code, and it came up in conversation. My flatmate tipped me off about the ‘dump’ feature of the svnadmin tool for use in backing up a repository.

    Dump is used to dump the contents of filesystem to stdout in a “dumpfile” portable format. Previously I’ve just been doing a file system copy of my repository directory, but I’ve never actually tested recovering from this and there are a number of things that could go wrong. The dump command is a safe way of backing up repository data, and can also be provided with various optimisation options.

    A dumped repository can then be restored using the svnadmin load command.

    An example (dumping a repository called source_code with a parent directory of /repos):

    $ cd /repos
    $ svnadmin dump source_code > source_code_dump
    #On second system:
    $svnadmin load source_code < source_code_dump
    

    The Subversion book refers to dump/load for migrating repositories from one version to another.