Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 9 Apr 2011 15:15:42 +0200
From:      Sami Kerola <>
Cc:        Roar Pettersen <>
Subject:   malloc: errno: 22: Invalid argument
Message-ID:  <>

Next in thread | Raw E-Mail | Index | Archive | Help
Hello FreeBSD answers,

I am a maintainer of a dhcp analysis software, which is before exit
checking errno. I got report from FreeBSD user, Roar who is CC:d, that
my software is reporting invalid argument at that section of the
program. After sending debugging messages back and forth issue was
pinpointed to following code sample.

-- snip
#include <err.h>
#include <errno.h>
#include <stdlib.h>

int main(void)
        int *i;
        warn("errno: %d", errno);
        i =3D malloc(sizeof(int));
        warn("errno: %d", errno);
        return (errno);
-- snip

which will give following output:

# ./a.out
a.out: errno: 0: Unknown error: 0
a.out: errno: 22: Invalid argument

Characteristics of the system are;


# gcc -v
Using built-in specs.
Target: i386-undermydesk-freebsd
Configured with: FreeBSD/i386 system compiler
Thread model: posix
gcc version 4.2.1 20070719  [FreeBSD]


There is no malloc.conf file on system.

I don't understand why the invalid argument is set. I do not feel
comfortable to write 'if the system is FreeBSD do not care malloc
related errno 22' to my code. That simply sounds wrong. Does someone
have explanation what might be going on and/or advice how I should
deal this thing in the code? Or is the whole thing some how
environment related?

Unfortunately I don't have FreeBSD installation. So even if you would
not be a malloc specialist you can say reply and tell that the sample
is or is not setting invalid argument. That will be evidence that the
problem happens either on none, some or all other systems as well.

Thanks in advance for help.

=A0=A0 Sami Kerola

Want to link to this message? Use this URL: <>