~ubuntu-branches/debian/sid/postfix/sid

« back to all changes in this revision

Viewing changes to src/util/dict_cidr.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones, LaMont Jones, localization folks
  • Date: 2014-02-11 07:44:30 UTC
  • mfrom: (1.1.41)
  • Revision ID: package-import@ubuntu.com-20140211074430-91tdwgjriazawdz4
Tags: 2.11.0-1
[LaMont Jones]

* New upstream release: 2.11.0

[localization folks]

* l10n: Updated German translations.  Closes: #734893 (Helge Kreutzmann)

Show diffs side-by-side

added added

removed removed

Lines of Context:
165
165
DICT   *dict_cidr_open(const char *mapname, int open_flags, int dict_flags)
166
166
{
167
167
    DICT_CIDR *dict_cidr;
168
 
    VSTREAM *map_fp;
 
168
    VSTREAM *map_fp = 0;
169
169
    struct stat st;
170
 
    VSTRING *line_buffer;
171
 
    VSTRING *why;
 
170
    VSTRING *line_buffer = 0;
 
171
    VSTRING *why = 0;
172
172
    DICT_CIDR_ENTRY *rule;
173
173
    DICT_CIDR_ENTRY *last_rule = 0;
174
174
    int     lineno = 0;
175
175
 
176
176
    /*
 
177
     * Let the optimizer worry about eliminating redundant code.
 
178
     */
 
179
#define DICT_CIDR_OPEN_RETURN(d) do { \
 
180
        DICT *__d = (d); \
 
181
        if (map_fp != 0 && vstream_fclose(map_fp)) \
 
182
            msg_fatal("cidr map %s: read error: %m", mapname); \
 
183
        if (line_buffer != 0) \
 
184
            vstring_free(line_buffer); \
 
185
        if (why != 0) \
 
186
            vstring_free(why); \
 
187
        return (__d); \
 
188
    } while (0)
 
189
 
 
190
    /*
177
191
     * Sanity checks.
178
192
     */
179
193
    if (open_flags != O_RDONLY)
180
 
        return (dict_surrogate(DICT_TYPE_CIDR, mapname, open_flags, dict_flags,
181
 
                               "%s:%s map requires O_RDONLY access mode",
182
 
                               DICT_TYPE_CIDR, mapname));
 
194
        DICT_CIDR_OPEN_RETURN(dict_surrogate(DICT_TYPE_CIDR, mapname,
 
195
                                             open_flags, dict_flags,
 
196
                                  "%s:%s map requires O_RDONLY access mode",
 
197
                                             DICT_TYPE_CIDR, mapname));
183
198
 
184
199
    /*
185
200
     * Open the configuration file.
186
201
     */
187
202
    if ((map_fp = vstream_fopen(mapname, O_RDONLY, 0)) == 0)
188
 
        return (dict_surrogate(DICT_TYPE_CIDR, mapname, open_flags, dict_flags,
189
 
                               "open %s: %m", mapname));
 
203
        DICT_CIDR_OPEN_RETURN(dict_surrogate(DICT_TYPE_CIDR, mapname,
 
204
                                             open_flags, dict_flags,
 
205
                                             "open %s: %m", mapname));
190
206
    if (fstat(vstream_fileno(map_fp), &st) < 0)
191
207
        msg_fatal("fstat %s: %m", mapname);
192
208
 
193
 
    /*
194
 
     * No early returns without memory leaks.
195
 
     */
196
209
    line_buffer = vstring_alloc(100);
197
210
    why = vstring_alloc(100);
198
211
 
224
237
        last_rule = rule;
225
238
    }
226
239
 
227
 
    /*
228
 
     * Clean up.
229
 
     */
230
 
    if (vstream_fclose(map_fp))
231
 
        msg_fatal("cidr map %s: read error: %m", mapname);
232
 
    vstring_free(line_buffer);
233
 
    vstring_free(why);
234
 
 
235
 
    return (DICT_DEBUG (&dict_cidr->dict));
 
240
    DICT_CIDR_OPEN_RETURN(DICT_DEBUG (&dict_cidr->dict));
236
241
}