Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ivan Sorokin <vanyacpp@gmail.com>
To: alsa-devel@alsa-project.org
Subject: Re: valgrind error in snd_tlv_get_dB_range
Date: Sun, 19 Jan 2014 16:22:47 +0400	[thread overview]
Message-ID: <52DBC397.5020704@gmail.com> (raw)
In-Reply-To: <52DBA5EB.3070104@gmail.com>

On 19.01.2014 14:16, Ivan Sorokin wrote:

> I tried to trace problem in snd_hctl_elem_tlv_read, but I failed to do
> so due to lack of experience with alsa-lib.
>
> Could someone more experienced with alsa-lib look at the problem?

After a bit more investigation I've found that tlv is initialized in 
snd_ctl_hw_elem_tlv with memcpy in line 245. This initialization looks 
perfectly correct. So perhaps this is a error in valgrind (unimplemented 
ioctl).

P.S. I believe I found a memory leak:

> 	switch (op_flag) {
> 	case -1: inum = SNDRV_CTL_IOCTL_TLV_COMMAND; break;
>  	case 0:	inum = SNDRV_CTL_IOCTL_TLV_READ; break;
> 	case 1:	inum = SNDRV_CTL_IOCTL_TLV_WRITE; break;
> 	default: return -EINVAL;
> 	}
> 	xtlv = malloc(sizeof(struct snd_ctl_tlv) + tlv_size);
> 	if (xtlv == NULL)
> 		return -ENOMEM;
> 	xtlv->numid = numid;
> 	xtlv->length = tlv_size;
> 	memcpy(xtlv->tlv, tlv, tlv_size);
> 	if (ioctl(hw->fd, inum, xtlv) < 0) {
> 		free(xtlv);
> 		return -errno;
> 	}
> 	if (op_flag == 0) {
> 		if (xtlv->tlv[1] + 2 * sizeof(unsigned int) > tlv_size)

missing free(xtlv) here

> 			return -EFAULT;
> 		memcpy(tlv, xtlv->tlv, xtlv->tlv[1] + 2 * sizeof(unsigned int));
> 	}
> 	free(xtlv);
> 	return 0;

  parent reply	other threads:[~2014-01-19 12:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-19 10:16 valgrind error in snd_tlv_get_dB_range Ivan Sorokin
2014-01-19 11:19 ` Clemens Ladisch
2014-01-19 12:22 ` Ivan Sorokin [this message]
2014-01-20  9:42   ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52DBC397.5020704@gmail.com \
    --to=vanyacpp@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox