mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Luca <groovysnail42@gmail.com>
To: musl@lists.openwall.com
Subject: [musl] Memory Leak
Date: Wed, 17 Jul 2024 18:54:59 +0200	[thread overview]
Message-ID: <CAND4rFaJyy4qEooADYHjFj3yF3wQaQ02GCX3u13_OJGOr1hu+w@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 512 bytes --]

Hi,

I believe I found a memory leak in your code.

In the file: /src/env/putenv.c

In the function: int __putenv(char *s, size_t l, char *r);

The variable `static char **oldenv` is passed to a free in line 29:
`free(oldenv);`.
The variable is a 2d pointer and therefore all contents within it should be
freed.
By freeing only oldenv all the lines of `__environ` are lost.

Possible hotfix:
```
for (int j = 0; oldenv[j]; ++j) free(oldenv[j]);
free(oldenv);
```

Thank you for your support and dedication,
Luca

[-- Attachment #2: Type: text/html, Size: 731 bytes --]

             reply	other threads:[~2024-07-17 17:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-17 16:54 Luca [this message]
2024-07-17 18:33 ` Markus Wichmann

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=CAND4rFaJyy4qEooADYHjFj3yF3wQaQ02GCX3u13_OJGOr1hu+w@mail.gmail.com \
    --to=groovysnail42@gmail.com \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).