lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] Dealloc in fs_close_custom()?


From: Giuseppe Modugno
Subject: Re: [lwip-users] Dealloc in fs_close_custom()?
Date: Wed, 28 Feb 2018 09:11:32 +0100
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0

Il 27/02/2018 08:54, Giuseppe Modugno ha scritto:
Il 27/02/2018 06:36, Simon Goldschmidt ha scritto:
Giuseppe Modugno wrote:
And another thing I couldn't explain. The example uses pextension pointer for malloc/free. However it sets file->data = file->pextension immediately.   So why don't use just file->data? It seems pextension is never used in lwip code.
Exactly. This is an example that wants to show you can use pextension for anything you like
as it is not used by lwIP code internally.

Using ->data only works for files in one piece.
Maybe I'm wrong, but here pextension and state void pointers are very, very similar. Maybe it's possible to reduce the complexity leaving only one member.

Considering the new prototype of httpd_cgi_handler(), this is more evident. Now we have struct fs_file pointer in CGI handler, so we can access ->pextension (that could be setup during fs_custom_open()). So the complexity of LWIP_HTTPD_FILE_STATE is IMHO completely useless.

int fs_open_custom(struct fs_file *file, const char *filename) {
  if (!strcmp(filename, "/custom.html")) {
    struct mystate_s *file_state = mem_malloc(sizeof(struct mystate_s));
    /* Init file_state members */
    file->pextension = file_state;
  }
}

void httpd_cgi_handler(struct fs_file *file, const char *uri, int iNumParams, char **pcParam, char **pcValue) {
  struct mystate_s *file_state = (struct mystate_s *)file->pextension;
  /* Access file_state members */
}

void fs_close_custom(struct fs_file *file) {
  if (file && file->pextension) mem_free(file->pextension);
  if (file) mem_free(file);
}







reply via email to

[Prev in Thread] Current Thread [Next in Thread]