From owner-freebsd-questions@FreeBSD.ORG Sat Apr 9 13:44:34 2011 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D74D1106564A for ; Sat, 9 Apr 2011 13:44:34 +0000 (UTC) (envelope-from kerolasa@gmail.com) Received: from mail-qw0-f54.google.com (mail-qw0-f54.google.com [209.85.216.54]) by mx1.freebsd.org (Postfix) with ESMTP id 8D4088FC0C for ; Sat, 9 Apr 2011 13:44:34 +0000 (UTC) Received: by qwc9 with SMTP id 9so2815557qwc.13 for ; Sat, 09 Apr 2011 06:44:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:reply-to:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=UnJ9K5hxptVgWj2p8DpnOo23fEXVwiVIse6ncdbko+w=; b=SZOpTP/YGwRSXxRTn6BfCj6dMkGk5vgR2dfoTYSXZ1SThhbNXvWUITNHJUCUQLrs21 MTiHrpVbdAZD/XoVA2C2OdktJ3c7fQzT/Cw3qwG8AkHcSxbU8CYYrofXDZHMW/6lKXyv NRwHSe50LftZyhCW4/TUswPdkCJAbX33oyWns= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:reply-to:date:x-google-sender-auth:message-id :subject:from:to:cc:content-type:content-transfer-encoding; b=npV6vRtbbp1kFVA40rMOFB3lwV0K8h6V1qoAs6hGZZ6OPmBfhA2Ij+DWPWF2Q52ZzT zcLsEF2YEodd8aE79lHNEu/CepljeoHukV4Tiy0YXI65SJgW02nyR0iKFCVizu13TJHi C3HtdDl8Tb6Ms0iatCLi1zRtpVUhfyMyC9QKg= MIME-Version: 1.0 Received: by 10.229.78.22 with SMTP id i22mr2797271qck.33.1302354942481; Sat, 09 Apr 2011 06:15:42 -0700 (PDT) Sender: kerolasa@gmail.com Received: by 10.229.96.137 with HTTP; Sat, 9 Apr 2011 06:15:42 -0700 (PDT) Date: Sat, 9 Apr 2011 15:15:42 +0200 X-Google-Sender-Auth: UMUlOgq3s8hAyqMHNG73h9BAz7o Message-ID: From: Sami Kerola To: freebsd-questions@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: Roar Pettersen Subject: malloc: errno: 22: Invalid argument X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: kerolasa@gmail.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 09 Apr 2011 13:44:34 -0000 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 #include #include int main(void) { int *i; warn("errno: %d", errno); i =3D malloc(sizeof(int)); warn("errno: %d", errno); free(i); 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; FreeBSD 8.2-STABLE # 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] /lib/libc.so.7 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. --=20 =A0=A0 Sami Kerola =A0=A0 http://www.iki.fi/kerolasa/