Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7850557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:53:48+00:00 2026-06-02T18:53:48+00:00

As a malloc wrapper, I use this classical snippet of code: #define _GNU_SOURCE #include

  • 0

As a malloc wrapper, I use this classical snippet of code:

#define _GNU_SOURCE
#include <stdio.h>
#include <stdint.h>
#include <dlfcn.h>

void* malloc(size_t size)
{
    static void* (*real_malloc)(size_t) = NULL;
    if (!real_malloc)
        real_malloc = dlsym(RTLD_NEXT, "malloc");

    void *p = real_malloc(size);
    fprintf(stderr, "malloc(%d) = %p\n", size, p);
    return p;
}

Valgrind is upset because there are buffers still allocated by dlsym at the end of the program.

==32691== 32 bytes in 1 blocks are still reachable in loss record 1 of 1
==32691==    at 0x4C279FC: calloc (vg_replace_malloc.c:467)
==32691==    by 0x528559F: _dlerror_run (dlerror.c:142)
==32691==    by 0x5285099: dlsym (dlsym.c:71)
==32691==    by 0x4060BC: malloc (memory.c:222)

How can I release those resources ?
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:53:50+00:00Added an answer on June 2, 2026 at 6:53 pm

    1 blocks are still reachable

    These blocks are just fine. You don’t need to worry about them, they are not leaks. There is nothing to see here, move along.

    It’s the “definitely lost” that you should care about.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am facing SIGEV with this malloc wrapper code, can anybody please help me?
I want to use the git's malloc and realloc wrappers in my code for
int test_malloc(void **ptr, size_t size) { (*ptr) = malloc(size); return 0; } int test_app()
Can someone explain me the working of a malloc wrapper for below code?? RTLD_NEXT
I have some code in C# which has a com wrapper. This com wrapper
What does malloc(0) return? Would the answer be same for realloc(malloc(0),0) ? #include<stdio.h> #include<malloc.h>
I would like to actually use this wrapper, but the problem is i don't
malloc defined like below: void *malloc(size_t size); http://pubs.opengroup.org/onlinepubs/009695399/functions/malloc.html size_t definition (stddef.h): size_t: Unsigned integer
I've never used malloc to store more than values but I have to use
I have a code that has a large number of malloc s and device-specific

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.