Fix: Des free était fait sur des ressources non allouées.

This commit is contained in:
Laurent Destailleur 2004-11-02 22:08:05 +00:00
parent 54c6f0873a
commit ddce1625b4

View File

@ -333,118 +333,120 @@ class Contact
* \param _id id du contact * \param _id id du contact
* \param user Utilisateur lié au contact pour une alerte * \param user Utilisateur lié au contact pour une alerte
*/ */
function fetch($_id, $user=0) function fetch($_id, $user=0)
{ {
$sql = "SELECT c.idp, c.fk_soc, c.civilite civilite_id, c.name, c.firstname, c.address, c.birthday as birthday, poste, phone, phone_perso, phone_mobile, fax, c.email, jabberid, c.note"; $sql = "SELECT c.idp, c.fk_soc, c.civilite civilite_id, c.name, c.firstname, c.address, c.birthday as birthday, poste, phone, phone_perso, phone_mobile, fax, c.email, jabberid, c.note";
$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c"; $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
$sql .= " WHERE c.idp = ". $_id; $sql .= " WHERE c.idp = ". $_id;
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
if ($this->db->num_rows()) if ($this->db->num_rows())
{ {
$obj = $this->db->fetch_object(); $obj = $this->db->fetch_object();
$this->id = $obj->idp; $this->id = $obj->idp;
$this->civilite_id = $obj->civilite_id; $this->civilite_id = $obj->civilite_id;
$this->name = $obj->name; $this->name = $obj->name;
$this->firstname = $obj->firstname; $this->firstname = $obj->firstname;
$this->nom = $obj->name; $this->nom = $obj->name;
$this->prenom = $obj->firstname; $this->prenom = $obj->firstname;
$this->address = $obj->address; $this->address = $obj->address;
$this->societeid = $obj->fk_soc; $this->societeid = $obj->fk_soc;
$this->socid = $obj->fk_soc; $this->socid = $obj->fk_soc;
$this->poste = $obj->poste; $this->poste = $obj->poste;
$this->fullname = $this->firstname . ' ' . $this->name; $this->fullname = $this->firstname . ' ' . $this->name;
$this->phone_pro = dolibarr_print_phone($obj->phone); $this->phone_pro = dolibarr_print_phone($obj->phone);
$this->fax = dolibarr_print_phone($obj->fax); $this->fax = dolibarr_print_phone($obj->fax);
$this->phone_perso = dolibarr_print_phone($obj->phone_perso); $this->phone_perso = dolibarr_print_phone($obj->phone_perso);
$this->phone_mobile = dolibarr_print_phone($obj->phone_mobile); $this->phone_mobile = dolibarr_print_phone($obj->phone_mobile);
$this->code = $obj->code; $this->code = $obj->code;
$this->email = $obj->email; $this->email = $obj->email;
$this->jabberid = $obj->jabberid; $this->jabberid = $obj->jabberid;
$this->mail = $obj->email; $this->mail = $obj->email;
$this->birthday = $obj->birthday; $this->birthday = $obj->birthday;
$this->birthday_alert = $obj->birthday_alert; $this->birthday_alert = $obj->birthday_alert;
$this->note = $obj->note; $this->note = $obj->note;
} }
$this->db->free(); $this->db->free();
$sql = "SELECT u.rowid "; $sql = "SELECT u.rowid ";
$sql .= " FROM ".MAIN_DB_PREFIX."user as u"; $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
$sql .= " WHERE u.fk_socpeople = ". $_id; $sql .= " WHERE u.fk_socpeople = ". $_id;
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
if ($this->db->num_rows()) if ($this->db->num_rows())
{ {
$uobj = $this->db->fetch_object(); $uobj = $this->db->fetch_object();
$this->user_id = $uobj->rowid; $this->user_id = $uobj->rowid;
} }
} $this->db->free();
$this->db->free(); }
else
{
$sql = "SELECT count(*) "; dolibarr_syslog("Error in Contact::fetch() sql=$sql");
$sql .= " FROM ".MAIN_DB_PREFIX."contact_facture"; }
$sql .= " WHERE fk_contact = ". $_id;
if ($this->db->query($sql)) $sql = "SELECT count(*) ";
{ $sql .= " FROM ".MAIN_DB_PREFIX."contact_facture";
if ($this->db->num_rows()) $sql .= " WHERE fk_contact = ". $_id;
{
$this->facturation = 1; if ($this->db->query($sql))
} {
else if ($this->db->num_rows())
{ {
$this->facturation = 0; $this->facturation = 1;
} }
} else
else {
{ $this->facturation = 0;
dolibarr_syslog("Error in Contact::fetch() id=$_id"); }
} $this->db->free();
}
$this->db->free(); else
{
if ($user) dolibarr_syslog("Error in Contact::fetch() sql=$sql");
{ }
$sql = "SELECT fk_user";
$sql .= " FROM ".MAIN_DB_PREFIX."user_alert"; if ($user)
$sql .= " WHERE fk_user = $user->id AND fk_contact = ".$_id; {
$sql = "SELECT fk_user";
if ($this->db->query($sql)) $sql .= " FROM ".MAIN_DB_PREFIX."user_alert";
{ $sql .= " WHERE fk_user = $user->id AND fk_contact = ".$_id;
if ($this->db->num_rows())
{ if ($this->db->query($sql))
$obj = $this->db->fetch_object(); {
if ($this->db->num_rows())
$this->birthday_alert = 1; {
} $obj = $this->db->fetch_object();
else
{ $this->birthday_alert = 1;
print $this->db->error(); }
dolibarr_syslog("Error in Contact::fetch() id=$_id"); $this->db->free();
} }
} else
} {
} dolibarr_syslog("Error in Contact::fetch() sql=$sql");
else }
{ }
dolibarr_syslog("Error in Contact::fetch() id=$_id"); }
print $this->db->error(); else
} {
dolibarr_syslog("Error in Contact::fetch() sql=$sql");
}
} }
/* /*
* \brief Efface le contacte de la base et éventuellement de l'annuaire LDAP * \brief Efface le contacte de la base et éventuellement de l'annuaire LDAP