# Unexpected usage of 'duplicate' flag in sapi_add_header_ex()

- Thread: https://externals.io/message/28658
- Original archive: https://news-web.php.net/php.internals/28658
- Started by ebgssth@gmail.com on 2007-04-03T15:26:54+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #28658 — ebgssth@gmail.com — 2007-04-03T15:26:54+00:00

URL: https://externals.io/message/28658#28658

Hi gurus.

Fiddling with PHP extensions I found the following code in
'sapi_add_header_ex()' in SAPI.c

   if (!duplicate)
       efree(header_line);

which makes me wonder because the other day I read CODING_STANDARD
included in PHP src which says

"[1] Functions that are given pointers to resources should not free them
*snip*
Exceptions:
 - The function's designated behavior is freeing that resource.  E.g. efree()
 - The function is given a boolean argument, that controls whether or not
   the function may free its arguments (if true - the function must free its
   arguments, if false - it must not)
*snip*
"
I felt the rule above is incompatible with how efree and duplicate
flag is used in
sapi_add_header_ex().

So my question is...
Is this intentional?
If so, any reason to break the coding standard in this instance?
and what does, in this context,  'duplicate' means?

Thanks you in advance.

---

## #28659 — Antony Dovgal — 2007-04-03T18:37:00+00:00

URL: https://externals.io/message/28658#28659 · In reply to: #28658

> Hi gurus.
> 
> Fiddling with PHP extensions I found the following code in
> 'sapi_add_header_ex()' in SAPI.c
> 
>    if (!duplicate)
>        efree(header_line);
> 
> which makes me wonder because the other day I read CODING_STANDARD
> included in PHP src which says
> 
> "[1] Functions that are given pointers to resources should not free them
> *snip*
> Exceptions:
>  - The function's designated behavior is freeing that resource.  E.g. efree()
>  - The function is given a boolean argument, that controls whether or not
>    the function may free its arguments (if true - the function must free its
>    arguments, if false - it must not)
> *snip*
> "
> I felt the rule above is incompatible with how efree and duplicate
> flag is used in
> sapi_add_header_ex().
> 
> So my question is...
> Is this intentional?

Apparently yes.

> If so, any reason to break the coding standard in this instance?

Standards are general rules, there might be some exceptions.
(It doesn't mean I personally like this code or encourage to ignore the standards).

> and what does, in this context,  'duplicate' means?

See main/main.c, line 1119 for example.
It might be convenient to free duplicated buffer and ignore static one.

-- 
Wbr,
Antony Dovgal

---

## #28670 — ebgssth@gmail.com — 2007-04-03T23:18:52+00:00

URL: https://externals.io/message/28658#28670 · In reply to: #28659

Hi Antony.

Thanks you for replying.

> > […]
>
> Standards are general rules, there might be some exceptions.
> (It doesn't mean I personally like this code or encourage to ignore the standards).
>
> > […]
>
> See main/main.c, line 1119 for example.
> It might be convenient to free duplicated buffer and ignore static one.

Then wouldn't it be nice call that flag static or no_duplicate or something?
I thought 'duplicate' is misleading name.

---

## #28671 — Antony Dovgal — 2007-04-04T08:07:28+00:00

URL: https://externals.io/message/28658#28671 · In reply to: #28670

> Hi Antony.
> 
> Thanks you for replying.
> 
> > […]
> 
> Then wouldn't it be nice call that flag static or no_duplicate or something?
> I thought 'duplicate' is misleading name.

Don't fix something that isn't broken.
There are a lot of places requiring attention, this is not one of them.

-- 
Wbr, 
Antony Dovgal
