jwerle / url.h

Parse URLs in C much like Node's url module.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

serious mem leak

takakawa opened this issue · comments

I have read the code,and find that there are many memory leak in it.
Such As some code in url_parse :


  char *search = malloc(sizeof(search));
  if (!search) return NULL;                               // you should not just return NULL,you should free previou malloced memroy
  tmp_path = strff(tmp_path, pathname_len);
  strcat(search, "");
  sscanf(tmp_path, "%[^#]", search);
  data->search = search;
  int search_len = strlen(search);
  free(tmp_path);

  char *query = malloc(sizeof(char));
  if (!query) return NULL;                            // you should not just return NULL,you should free previou malloced memroy
  sscanf(search, "?%s", query);
  data->query = query;

  char *hash = malloc(sizeof(char));
  if (!hash) return NULL;                     // you should not just return NULL,you should free previou malloced memroy

The memory leaks are fixed now.