GithubHelp home page GithubHelp logo

C: cleanup attribute not supported about infer HOT 4 OPEN

facebook avatar facebook commented on April 26, 2024 1
C: cleanup attribute not supported

from infer.

Comments (4)

dulmarod avatar dulmarod commented on April 26, 2024

Hi,
Thanks for reporting this. We haven't looked into the cleanup attribute yet, but would be happy to support it. Could you please give us some small example of how this attribute is used and what kind of false positive leaks you get?
Thanks,
Dulma

from infer.

phomes avatar phomes commented on April 26, 2024

Hi,
Here is an example of how to use it. When a variable with the attribute goes out of scope the function specified with the cleanup attribute will be called. The typical usecase is for free'ing the variable. This saves us from manually freeing in all error cases etc.

#include <stdlib.h>
#include <string.h>

void my_cleanup_func(char **c)
{
  puts("debug: cleanup_func called");
  free(*c);
}

int main(int argc, char **argv)
{
  __attribute__ ((cleanup(my_cleanup_func))) char *s = NULL;

  s = strdup("demo string");

  return 0; /* s goes out of scope. Cleanup function called - no leak */
}

from infer.

vavrusa avatar vavrusa commented on April 26, 2024

It'd be great to support this, as it can't be easily modeled by a function or a macro.

from infer.

iphydf avatar iphydf commented on April 26, 2024

This is equivalent to C++ scope bound resource management, i.e. a class with a destructor.

from infer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.