Hi all,

I'm trying to understand the implementation of the pipemap: lookup function dict_pipe_lookup() [1]. Currently it copies the input query and pipeline stage outputs to a scratch buffer, and passes the buffer as the query for the next stage (or returns the buffer if there are no more stages).

My question: Why copy the string? Why not simply pass the previous stage's result pointer as the query for the next stage (or return it to the caller)? See the attached patch for what I mean. Is it because a table implementation is allowed to invalidate the result memory from a previous lookup before it reads the current query?

Thanks,
Richard

[1] https://github.com/vdukhovni/postfix/blob/32475272ffd1d92ecb03f60bf445ef17669205b7/postfix/src/util/dict_pipe.c#L69-L87
diff --git a/src/util/dict_pipe.c b/src/util/dict_pipe.c
index 8ce0faad7..d02eef8b6 100644
--- a/src/util/dict_pipe.c
+++ b/src/util/dict_pipe.c
@@ -59,11 +59,8 @@
 typedef struct {
     DICT    dict;			/* generic members */
     ARGV   *map_pipe;			/* pipelined tables */
-    VSTRING *qr_buf;			/* query/reply buffer */
 } DICT_PIPE;
 
-#define STR(x) vstring_str(x)
-
 /* dict_pipe_lookup - search pipelined tables */
 
 static const char *dict_pipe_lookup(DICT *dict, const char *query)
@@ -75,15 +72,13 @@ static const char *dict_pipe_lookup(DICT *dict, const char *query)
     char   *dict_type_name;
     const char *result = 0;
 
-    vstring_strcpy(dict_pipe->qr_buf, query);
     for (cpp = dict_pipe->map_pipe->argv; (dict_type_name = *cpp) != 0; cpp++) {
 	if ((map = dict_handle(dict_type_name)) == 0)
 	    msg_panic("%s: dictionary \"%s\" not found", myname, dict_type_name);
-	if ((result = dict_get(map, STR(dict_pipe->qr_buf))) == 0)
+	if ((result = dict_get(map, result ? result : query)) == 0)
 	    DICT_ERR_VAL_RETURN(dict, map->error, result);
-	vstring_strcpy(dict_pipe->qr_buf, result);
     }
-    DICT_ERR_VAL_RETURN(dict, DICT_ERR_NONE, STR(dict_pipe->qr_buf));
+    DICT_ERR_VAL_RETURN(dict, DICT_ERR_NONE, result);
 }
 
 /* dict_pipe_close - disassociate from pipelined tables */
@@ -97,7 +92,6 @@ static void dict_pipe_close(DICT *dict)
     for (cpp = dict_pipe->map_pipe->argv; (dict_type_name = *cpp) != 0; cpp++)
 	dict_unregister(dict_type_name);
     argv_free(dict_pipe->map_pipe);
-    vstring_free(dict_pipe->qr_buf);
     dict_free(dict);
 }
 
@@ -182,7 +176,6 @@ DICT   *dict_pipe_open(const char *name, int open_flags, int dict_flags)
     dict_pipe->dict.close = dict_pipe_close;
     dict_pipe->dict.flags = dict_flags | match_flags;
     dict_pipe->dict.owner = aggr_owner;
-    dict_pipe->qr_buf = vstring_alloc(100);
     dict_pipe->map_pipe = argv;
     argv = 0;
     DICT_PIPE_RETURN(DICT_DEBUG (&dict_pipe->dict));
_______________________________________________
Postfix-devel mailing list -- postfix-devel@postfix.org
To unsubscribe send an email to postfix-devel-le...@postfix.org

Reply via email to