r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation
[samba.git] / source3 / libsmb / libsmb_cache.c
index df02cf3718f464471c68929097a76136111821de..ddb27535233abc12488d12085a0b365f6c41dda1 100644 (file)
@@ -27,7 +27,7 @@
  * Define this to get the real SMBCFILE and SMBCSRV structures 
  */
 #define _SMBC_INTERNAL
-#include "libsmbclient.h"
+#include "include/libsmbclient.h"
 
 /*
  * Structure we use if internal caching mechanism is used 
@@ -50,12 +50,12 @@ struct smbc_server_cache {
  * This function is only used if the external cache is not enabled 
  */
 static int smbc_add_cached_server(SMBCCTX * context, SMBCSRV * new,
-                                 char * server, char * share, 
-                                 char * workgroup, char * username)
+                                 const char * server, const char * share, 
+                                 const char * workgroup, const char * username)
 {
        struct smbc_server_cache * srvcache = NULL;
 
-       if (!(srvcache = malloc(sizeof(*srvcache)))) {
+       if (!(srvcache = SMB_MALLOC_P(struct smbc_server_cache))) {
                errno = ENOMEM;
                DEBUG(3, ("Not enough space for server cache allocation\n"));
                return 1;
@@ -65,25 +65,25 @@ static int smbc_add_cached_server(SMBCCTX * context, SMBCSRV * new,
 
        srvcache->server = new;
 
-       srvcache->server_name = strdup(server);
+       srvcache->server_name = SMB_STRDUP(server);
        if (!srvcache->server_name) {
                errno = ENOMEM;
                goto failed;
        }
 
-       srvcache->share_name = strdup(share);
+       srvcache->share_name = SMB_STRDUP(share);
        if (!srvcache->share_name) {
                errno = ENOMEM;
                goto failed;
        }
 
-       srvcache->workgroup = strdup(workgroup);
+       srvcache->workgroup = SMB_STRDUP(workgroup);
        if (!srvcache->workgroup) {
                errno = ENOMEM;
                goto failed;
        }
 
-       srvcache->username = strdup(username);
+       srvcache->username = SMB_STRDUP(username);
        if (!srvcache->username) {
                errno = ENOMEM;
                goto failed;
@@ -108,8 +108,8 @@ static int smbc_add_cached_server(SMBCCTX * context, SMBCSRV * new,
  * returns server_fd on success, -1 on error (not found)
  * This function is only used if the external cache is not enabled 
  */
-static SMBCSRV * smbc_get_cached_server(SMBCCTX * context, char * server, 
-                                 char * share, char * workgroup, char * user)
+static SMBCSRV * smbc_get_cached_server(SMBCCTX * context, const char * server, 
+                                 const char * share, const char * workgroup, const char * user)
 {
        struct smbc_server_cache * srv = NULL;
        
@@ -159,10 +159,15 @@ static int smbc_remove_cached_server(SMBCCTX * context, SMBCSRV * server)
  */
 static int smbc_purge_cached(SMBCCTX * context)
 {
-       struct smbc_server_cache * srv = NULL;
+       struct smbc_server_cache * srv;
+       struct smbc_server_cache * next;
        int could_not_purge_all = 0;
 
-       for (srv=((struct smbc_server_cache *) context->server_cache);srv;srv=srv->next) {
+       for (srv = ((struct smbc_server_cache *) context->server_cache),
+                 next = (srv ? srv->next :NULL);
+             srv;
+             srv = next, next = (srv ? srv->next : NULL)) {
+
                if (smbc_remove_unused_server(context, srv->server)) {
                        /* could not be removed */
                        could_not_purge_all = 1;