GithubHelp home page GithubHelp logo

Comments (4)

mereacre avatar mereacre commented on June 4, 2024

@aloisklink I had a look at the function and it seems that it has one memory leak and possibility to free a memory region which is not supposed to be freed by the uwrt_lookup_package.

Memory leek :)

if ((ti = os_calloc(1, sizeof(struct uci_type_list))) == NULL) {
- when it allocates a struct uci_type_list causing a memory leak

Freeing a pointer which is not supposed to be freed:

ret = s->e.name;

The pointer is freed here:

if (typestr != NULL) {

Solution memory leak:

Add a sys_free(ti) here


and remove the below line (no idea why is the purpose of it)
ti->idx++;

Solution for freeing the wrong pointer:

Replace the below line with

ret = s->e.name;

ret = sys_strdup(s->e.name)

from edgesec.

aloisklink avatar aloisklink commented on June 4, 2024

Memory leek :)

๐Ÿฅฌ๐Ÿง… ๐Ÿ˜†

(Unfortunately, the Unicodeยฎ consortium rejected all three proposals for a leek emoji, so instead I have to combine ๐Ÿฅฌ and ๐Ÿง… ๐Ÿ˜ญ)

Solution memory leak

Your solution sounds good! Feel free to make a PR (although use os_free or just plain free() instead of sys_free())!

Freeing a pointer which is not supposed to be freed:

Actually, I don't think this is an issue. In the function uci_lookup_section_ref(), you don't need to free() the return value. Instead, you need to free(*typestr);

E.g. this is how I believe the function needs to be used:

char *malloced_memory = NULL;
const char *return_value = uci_lookup_section_ref(A, B, &malloced_memory);
free(malloced_memory); // only allocated if need be

I can make a PR that documents this behaviour.

from edgesec.

mereacre avatar mereacre commented on June 4, 2024

Feel free to make PR.

from edgesec.

aloisklink avatar aloisklink commented on June 4, 2024

and remove the below line (no idea why is the purpose of it)

ti->idx++;

I've figured out the purpose of it (see PR #485 for a fix!)

Basically, if you call this function again with a different section that has the same type as a previous UCI section, it should print @section_name[0], @section_name[1], @section_name[2], ...:

image

But since we weren't saving the increment, it was always doing @section_name[0], @section_name[0], @section_name[0] (0 each time!).

from edgesec.

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.