Simon Josefsson <si...@josefsson.org> writes:

> Daniel Stenberg <dan...@haxx.se> writes:
>
>> On Tue, 5 Oct 2010, Simon Josefsson wrote:
>>
>>> +LIBSSH2_API void
>>> +libssh2_free(void *ptr)
>>> +{
>>> +  free (ptr);
>>> +}
>>
>> I think it's too simple. For example, to be able to free the memory
>> returned by libssh2_base64_decode() it would have to use the internal
>> LIBSSH2_FREE() call which needs the session pointer (and will then use
>> the correct free callback).
>
> Yeah, I thought about that, but kind of preferred the other way around
> to avoid the LIBSSH2_SESSION dependency.  But I guess the library is
> already too deeply married into the LIBSSH2_SESSION parameter anyway
> that it doesn't make any sense to try and avoid it here.  I can prepare
> an updated patch tomorrow..

I have pushed the patch below.  I now realize there should be a man page
too, will add it next...

/Simon

>From 98e38c4f3ac4ac973ea5929a6fa8d595cc003aa5 Mon Sep 17 00:00:00 2001
From: Simon Josefsson <si...@josefsson.org>
Date: Wed, 13 Oct 2010 15:19:12 +0200
Subject: [PATCH] Add libssh2_free.

---
 NEWS              |    4 ++++
 include/libssh2.h |    7 +++++++
 src/misc.c        |    7 +++++++
 3 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/NEWS b/NEWS
index f706192..b907919 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,7 @@
+This release includes the following changes:
+
+ o Added libssh2_free()
+
 libssh2 1.2.7 (August 17, 2010)
 
 This release includes the following changes:
diff --git a/include/libssh2.h b/include/libssh2.h
index 6040ab8..9d1e565 100644
--- a/include/libssh2.h
+++ b/include/libssh2.h
@@ -420,6 +420,13 @@ LIBSSH2_API int libssh2_init(int flags);
  */
 LIBSSH2_API void libssh2_exit(void);
 
+/*
+ * libssh2_free()
+ *
+ * Deallocate memory allocated by earlier call to libssh2 functions.
+ */
+LIBSSH2_API void libssh2_free(LIBSSH2_SESSION *session, void *ptr)
+
 /* Session API */
 LIBSSH2_API LIBSSH2_SESSION *
 libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)),
diff --git a/src/misc.c b/src/misc.c
index 7a92492..8809b6b 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -1,5 +1,6 @@
 /* Copyright (c) 2004-2007 Sara Golemon <sa...@libssh2.org>
  * Copyright (c) 2009 by Daniel Stenberg
+ * Copyright (c) 2010  Simon Josefsson
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms,
@@ -352,6 +353,12 @@ size_t _libssh2_base64_encode(LIBSSH2_SESSION *session,
 }
 /* ---- End of Base64 Encoding ---- */
 
+LIBSSH2_API void
+libssh2_free(LIBSSH2_SESSION *session, void *ptr)
+{
+    LIBSSH2_FREE(session, ptr);
+}
+
 #ifdef LIBSSH2DEBUG
 LIBSSH2_API int
 libssh2_trace(LIBSSH2_SESSION * session, int bitmask)
-- 
1.7.1

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel

Reply via email to