summaryrefslogtreecommitdiff
path: root/source3/smbd/statcache.c
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2003-03-17 03:47:15 +0000
committerAndrew Bartlett <abartlet@samba.org>2003-03-17 03:47:15 +0000
commit1171b0c9ac59e7bd667bb82f48cda27c203721d8 (patch)
tree89ac2e8e56967c086d0a6c0472ff58dbc1217a2d /source3/smbd/statcache.c
parent3ecf5d663864cab17288b73426183e1a1499e37c (diff)
downloadsamba-1171b0c9ac59e7bd667bb82f48cda27c203721d8.tar.gz
samba-1171b0c9ac59e7bd667bb82f48cda27c203721d8.tar.bz2
samba-1171b0c9ac59e7bd667bb82f48cda27c203721d8.zip
Fix memory leaks and add parinoioa code to our stat() cache.
Andrew Bartlett (This used to be commit 3fd07bd25eefdb2a7a6891fa1169ab2425607249)
Diffstat (limited to 'source3/smbd/statcache.c')
-rw-r--r--source3/smbd/statcache.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/source3/smbd/statcache.c b/source3/smbd/statcache.c
index 812e0dde37..57ba6ada81 100644
--- a/source3/smbd/statcache.c
+++ b/source3/smbd/statcache.c
@@ -90,14 +90,28 @@ void stat_cache_add( char *full_orig_name, char *orig_translated_path)
}
original_path = strdup(full_orig_name);
- if (!original_path)
+ if (!original_path) {
+ SAFE_FREE(translated_path);
return;
+ }
original_path_length = strlen(original_path);
+ if(original_path[original_path_length-1] == '/') {
+ original_path[original_path_length-1] = '\0';
+ original_path_length--;
+ }
+
if(!case_sensitive)
strupper(original_path);
-
+
+ if(!(original_path_length == translated_path_length)) {
+ DEBUG(0, ("OOPS - tried to store stat cache entry for non-equal length paths [%s] %u and [%s] %u)!\n", original_path, original_path_length, translated_path, translated_path_length));
+ SAFE_FREE(original_path);
+ SAFE_FREE(translated_path);
+ return;
+ }
+
#if 0
/*
* We will only replace namelen characters
@@ -119,6 +133,8 @@ void stat_cache_add( char *full_orig_name, char *orig_translated_path)
found_scp = (stat_cache_entry *)(hash_elem->value);
if (strcmp((found_scp->translated_path), orig_translated_path) == 0) {
/* already in hash table */
+ SAFE_FREE(original_path);
+ SAFE_FREE(translated_path);
return;
}
/* hash collision - remove before we re-add */
@@ -133,6 +149,8 @@ void stat_cache_add( char *full_orig_name, char *orig_translated_path)
+original_path_length
+translated_path_length)) == NULL) {
DEBUG(0,("stat_cache_add: Out of memory !\n"));
+ SAFE_FREE(original_path);
+ SAFE_FREE(translated_path);
return;
}
@@ -144,6 +162,9 @@ void stat_cache_add( char *full_orig_name, char *orig_translated_path)
hash_insert(&stat_cache, (char *)scp, original_path);
+ SAFE_FREE(original_path);
+ SAFE_FREE(translated_path);
+
DEBUG(5,("stat_cache_add: Added entry %s -> %s\n", scp->original_path, scp->translated_path));
}