Re: [E-devel] Ecore patch: ecore_file_download memory leak

2007-11-07 Thread Vinicius Gomes
Sorry folks, my firefox thought the patch was a binary and it was ignored.

On 11/7/07, Vinicius Gomes <[EMAIL PROTECTED]> wrote:
> Hi,
>
> This fixes a memory leak in the ecore_file_download function. The
> string returned by ecore_file_dir_get (that was strdup'd) was not
> being freed. Also, removing whitespaces at the end of some lines.
>
> --
> Vinicius
>
>


-- 
Vinicius
Index: src/lib/ecore_file/ecore_file_download.c
===
RCS file: /var/cvs/e/e17/libs/ecore/src/lib/ecore_file/ecore_file_download.c,v
retrieving revision 1.16
diff -u -r1.16 ecore_file_download.c
--- src/lib/ecore_file/ecore_file_download.c6 Aug 2007 20:00:28 -   
1.16
+++ src/lib/ecore_file/ecore_file_download.c7 Nov 2007 20:05:41 -
@@ -90,7 +90,7 @@
 
if (!_job_list)
  return;
-   
+
ecore_list_first_goto(_job_list);
while ((job = ecore_list_next(_job_list)))
  {
@@ -116,7 +116,7 @@
  *
  * You must provide the full url, including 'http://', 'ftp://' or 'file://'.\n
  * If @p dst already exist it will not be overwritten and the function will 
fail.\n
- * Ecore must be compiled with CURL to download using http and ftp protocols. 
+ * Ecore must be compiled with CURL to download using http and ftp protocols.
  */
 EAPI int
 ecore_file_download(const char *url, const char *dst,
@@ -124,7 +124,17 @@
int (*progress_cb)(void *data, const char *file, long int 
dltotal, long int dlnow, long int ultotal, long int ulnow),
void *data)
 {
-   if (!ecore_file_is_dir(ecore_file_dir_get((char *)dst))) return 0;
+   if (dst == NULL) return 0;
+
+   char *path = ecore_file_dir_get((char *) dst);
+
+   if (!ecore_file_is_dir(path))
+ {
+free(path);
+return 0;
+ }
+   free(path);
+
if (ecore_file_exists(dst)) return 0;
 
/* FIXME: Add handlers for http and ftp! */
@@ -145,7 +155,7 @@
  {
/* download */
Ecore_File_Download_Job *job;
-   
+
job = _ecore_file_download_curl(url, dst, completion_cb, progress_cb, 
data);
if (job)
  return 1;
@@ -170,7 +180,7 @@
  * @return 1 if protocol is handled or 0 if not
  *
  * @p protocol can be 'http://', 'ftp://' or 'file://'.\n
- * Ecore must be compiled with CURL to handle http and ftp protocols. 
+ * Ecore must be compiled with CURL to handle http and ftp protocols.
  */
 EAPI int
 ecore_file_download_protocol_available(const char *protocol)
@@ -185,15 +195,15 @@
 }
 
 #ifdef HAVE_CURL
-/* this reports the downloads progress. if we return 0, then download 
+/* this reports the downloads progress. if we return 0, then download
  * continues, if we return anything else, then the download stops */
 static int
 _ecore_file_download_curl_progress_func(void *clientp, double dltotal, double 
dlnow, double ultotal, double ulnow)
-{  
+{
Ecore_File_Download_Job *job;
-   
+
job = clientp;
-   
+
if(job->progress_cb)
  return job->progress_cb(job->data, job->dst, (long int)dltotal, (long 
int)dlnow, (long int)ultotal, (long int)ulnow);
return 0;
@@ -203,9 +213,9 @@
 _ecore_file_download_curl(const char *url, const char *dst,
  void (*completion_cb)(void *data, const char *file,
int status),
- int (*progress_cb)(void *data, const char *file, 
+ int (*progress_cb)(void *data, const char *file,
 long int dltotal, long int dlnow,
-long int ultotal, 
+long int ultotal,
 long int ulnow),
  void *data)
 {
@@ -234,17 +244,17 @@
free(job);
return NULL;
  }
-   
+
curl_easy_setopt(job->curl, CURLOPT_URL, url);
curl_easy_setopt(job->curl, CURLOPT_WRITEDATA, job->file);
-   
+
if (progress_cb)
  {
-   curl_easy_setopt(job->curl, CURLOPT_NOPROGRESS, FALSE);   
-   curl_easy_setopt(job->curl, CURLOPT_PROGRESSDATA, job);   
+   curl_easy_setopt(job->curl, CURLOPT_NOPROGRESS, FALSE);
+   curl_easy_setopt(job->curl, CURLOPT_PROGRESSDATA, job);
curl_easy_setopt(job->curl, CURLOPT_PROGRESSFUNCTION, 
_ecore_file_download_curl_progress_func);
  }
-   
+
job->data = data;
job->completion_cb = completion_cb;
job->progress_cb = progress_cb;
-
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/___

[E-devel] Ecore patch: ecore_file_download memory leak

2007-11-07 Thread Vinicius Gomes
Hi,

This fixes a memory leak in the ecore_file_download function. The
string returned by ecore_file_dir_get (that was strdup'd) was not
being freed. Also, removing whitespaces at the end of some lines.

--
Vinicius
-
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/___
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel